HeartSaVioR commented on a change in pull request #23912: [SPARK-21029][SS] 
StreamingQuery should be stopped when the SparkSession is stopped
URL: https://github.com/apache/spark/pull/23912#discussion_r264128027
 
 

 ##########
 File path: core/src/main/scala/org/apache/spark/SparkContext.scala
 ##########
 @@ -1856,9 +1867,22 @@ class SparkContext(config: SparkConf) extends Logging {
       throw new SparkException(s"Cannot stop SparkContext within listener bus 
thread.")
     }
     // Use the stopping variable to ensure no contention for the stop scenario.
-    // Still track the stopped variable for use elsewhere in the code.
+    if (!stopping.compareAndSet(false, true)) {
+      if (stopped.get()) {
+        logInfo("SparkContext already stopped.")
+      } else {
+        logInfo("SparkContext is being stopped.")
+      }
+      return
+    }
+    stopHooks.synchronized {
+      stopHooks.forEach {
+        hook => Try(Utils.logUncaughtExceptions(hook()))
+      }
+    }
     if (!stopped.compareAndSet(false, true)) {
-      logInfo("SparkContext already stopped.")
+      // this should not happen
+      logError("SparkContext already stopped.")
 
 Review comment:
   Same message with different log level might confuse us. If we would like to 
leave error message because it should not reach here, explaining situation 
would not hurt since its level is ERROR.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to