Skip to content

Commit bdbe5da

Browse files
committed
Stop SparkContext after stopping scheduler, not before.
1 parent 03e9c40 commit bdbe5da

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

streaming/src/main/scala/org/apache/spark/streaming/StreamingContext.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,6 @@ class StreamingContext private[streaming] (
492492
* received data to be completed
493493
*/
494494
def stop(stopSparkContext: Boolean, stopGracefully: Boolean): Unit = synchronized {
495-
// Even if the streaming context has not been started, we still need to stop the SparkContext.
496-
// Even if we have already stopped, we still need to attempt to stop the SparkContext because
497-
// a user might stop(stopSparkContext = false) and then call stop(stopSparkContext = true).
498-
if (stopSparkContext) sc.stop()
499495
if (state == Stopped) {
500496
logWarning("StreamingContext has already been stopped")
501497
} else {
@@ -507,6 +503,10 @@ class StreamingContext private[streaming] (
507503
waiter.notifyStop()
508504
}
509505
}
506+
// Even if the streaming context has not been started, we still need to stop the SparkContext.
507+
// Even if we have already stopped, we still need to attempt to stop the SparkContext because
508+
// a user might stop(stopSparkContext = false) and then call stop(stopSparkContext = true).
509+
if (stopSparkContext) sc.stop()
510510
// The state should always be Stopped after calling `stop()`, even if we haven't started yet:
511511
state = Stopped
512512
}

0 commit comments

Comments
 (0)