Skip to content

Commit bedaead

Browse files
committed
Fix a race condition when reporting ExecutorState in the shutdown hook
1 parent 24d3357 commit bedaead

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

core/src/main/scala/org/apache/spark/deploy/LocalSparkCluster.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class LocalSparkCluster(
7575
// Stop the workers before the master so they don't get upset that it disconnected
7676
workerRpcEnvs.foreach(_.shutdown())
7777
masterRpcEnvs.foreach(_.shutdown())
78+
workerRpcEnvs.foreach(_.awaitTermination())
79+
masterRpcEnvs.foreach(_.awaitTermination())
7880
masterRpcEnvs.clear()
7981
workerRpcEnvs.clear()
8082
}

core/src/main/scala/org/apache/spark/deploy/worker/ExecutorRunner.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ private[deploy] class ExecutorRunner(
7171
workerThread.start()
7272
// Shutdown hook that kills actors on shutdown.
7373
shutdownHook = ShutdownHookManager.addShutdownHook { () =>
74+
// It's possible that we arrive here before calling `fetchAndRunExecutor`, then `state` will
75+
// be `ExecutorState.RUNNING`. In this case, we should set `state` to `FAILED`.
76+
if (state == ExecutorState.RUNNING) {
77+
state = ExecutorState.FAILED
78+
}
7479
killProcess(Some("Worker shutting down")) }
7580
}
7681

0 commit comments

Comments
 (0)