Skip to content

Commit 0d0fa86

Browse files
LuciferYangdongjoon-hyun
authored andcommitted
[SPARK-50578][PYTHON][SS][FOLLOWUP] Change to use Thread.interrupt instead of Thread.stop to interrupt the execution of TransformWithStateInPandasPythonPreInitRunner#daemonThread
### What changes were proposed in this pull request? This PR change to use `Thread.interrupt()` instead of `Thread.stop()` to attempt to interrupt the execution of `TransformWithStateInPandasPythonPreInitRunner#daemonThread`. Additionally, logic has been added in `TransformWithStateInPandasStateServer#run` to respond to the interrupt by setting the `CLOSED` state and exiting. ### Why are the changes needed? The `Thread.stop` method in Java 21 directly throws an `UnsupportedOperationException`, which led to the failure of the Java 21 daily tests: - https://github.com/apache/spark/actions/runs/12511573912/job/34903859772 - https://github.com/apache/spark/actions/runs/12523542188/job/34933207012 - https://github.com/apache/spark/actions/runs/12592534465/job/35097321533 ![image](https://github.com/user-attachments/assets/75cef6d7-d66a-4652-b01d-38412d6db3b0) So the primary purpose of this change is to restore the daily tests for Java 21. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? - Pass GitHub Actions - Pass Java 21 GitHub Action test: https://github.com/LuciferYang/spark/actions/runs/12606699142/job/35137180872 ![image](https://github.com/user-attachments/assets/9e5e8b08-d167-4f7a-959c-8ebe6e22f9bc) ### Was this patch authored or co-authored using generative AI tooling? No Closes #49354 from LuciferYang/java21-test-2. Authored-by: yangjie01 <yangjie01@baidu.com> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
1 parent 98dc763 commit 0d0fa86

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/python/TransformWithStateInPandasPythonRunner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class TransformWithStateInPandasPythonPreInitRunner(
275275
override def stop(): Unit = {
276276
super.stop()
277277
closeServerSocketChannelSilently(stateServerSocket)
278-
daemonThread.stop()
278+
daemonThread.interrupt()
279279
}
280280

281281
private def startStateServer(): Unit = {

sql/core/src/main/scala/org/apache/spark/sql/execution/python/TransformWithStateInPandasStateServer.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ class TransformWithStateInPandasStateServer(
146146

147147
while (listeningSocket.isConnected &&
148148
statefulProcessorHandle.getHandleState != StatefulProcessorHandleState.CLOSED) {
149+
if (Thread.currentThread().isInterrupted) {
150+
throw new InterruptedException("Thread was interrupted")
151+
}
149152
try {
150153
val version = inputStream.readInt()
151154
if (version != -1) {
@@ -159,6 +162,11 @@ class TransformWithStateInPandasStateServer(
159162
logWarning(log"No more data to read from the socket")
160163
statefulProcessorHandle.setHandleState(StatefulProcessorHandleState.CLOSED)
161164
return
165+
case _: InterruptedException =>
166+
logInfo(log"Thread interrupted, shutting down state server")
167+
Thread.currentThread().interrupt()
168+
statefulProcessorHandle.setHandleState(StatefulProcessorHandleState.CLOSED)
169+
return
162170
case e: Exception =>
163171
logError(log"Error reading message: ${MDC(LogKeys.ERROR, e.getMessage)}", e)
164172
sendResponse(1, e.getMessage)

0 commit comments

Comments
 (0)