Skip to content

Commit 68e29ba

Browse files
HeartSaVioRdongjoon-hyun
authored andcommitted
[SPARK-29046][SQL][2.4] Fix NPE in SQLConf.get when active SparkContext is stopping
### What changes were proposed in this pull request? This patch fixes the bug regarding NPE in SQLConf.get, which is only possible when SparkContext._dagScheduler is null due to stopping SparkContext. The logic doesn't seem to consider active SparkContext could be in progress of stopping. Note that it can't be encountered easily as SparkContext.stop() blocks the main thread, but there're many cases which SQLConf.get is accessed concurrently while SparkContext.stop() is executing - users run another threads, or listener is accessing SQLConf.get after dagScheduler is set to null (this is the case what I encountered.) ### Why are the changes needed? The bug brings NPE. ### Does this PR introduce any user-facing change? No ### How was this patch tested? Previous patch #25753 was tested with new UT, and due to disruption with other tests in concurrent test run, the test is excluded in this patch. Closes #25798 from HeartSaVioR/SPARK-29046-branch-2.4. Authored-by: Jungtaek Lim (HeartSaVioR) <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 1c57da3 commit 68e29ba

File tree

1 file changed

+2
-1
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/internal

1 file changed

+2
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ object SQLConf {
130130
new ReadOnlySQLConf(TaskContext.get())
131131
} else {
132132
val isSchedulerEventLoopThread = SparkContext.getActive
133-
.map(_.dagScheduler.eventProcessLoop.eventThread)
133+
.flatMap { sc => Option(sc.dagScheduler) }
134+
.map(_.eventProcessLoop.eventThread)
134135
.exists(_.getId == Thread.currentThread().getId)
135136
if (isSchedulerEventLoopThread) {
136137
// DAGScheduler event loop thread does not have an active SparkSession, the `confGetter`

0 commit comments

Comments
 (0)