Skip to content

Commit ab97db7

Browse files
kotlovsdongjoon-hyun
authored andcommitted
[SPARK-34674][CORE][K8S] Close SparkContext after the Main method has finished
### What changes were proposed in this pull request? Close SparkContext after the Main method has finished, to allow SparkApplication on K8S to complete ### Why are the changes needed? if I don't call the method sparkContext.stop() explicitly, then a Spark driver process doesn't terminate even after its Main method has been completed. This behaviour is different from spark on yarn, where the manual sparkContext stopping is not required. It looks like, the problem is in using non-daemon threads, which prevent the driver jvm process from terminating. So I have inserted code that closes sparkContext automatically. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Manually on the production AWS EKS environment in my company. Closes #32081 from kotlovs/close-spark-context-on-exit. Authored-by: skotlov <skotlov@joom.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
1 parent 5013171 commit ab97db7

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,12 @@ private[spark] class SparkSubmit extends Logging {
952952
} catch {
953953
case t: Throwable =>
954954
throw findCause(t)
955+
} finally {
956+
try {
957+
SparkContext.getActive.foreach(_.stop())
958+
} catch {
959+
case e: Throwable => logError(s"Failed to close SparkContext: $e")
960+
}
955961
}
956962
}
957963

0 commit comments

Comments
 (0)