Github user felixcheung commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9116#discussion_r42080466
  
    --- Diff: 
streaming/src/main/scala/org/apache/spark/streaming/StreamingContext.scala ---
    @@ -694,31 +694,39 @@ class StreamingContext private[streaming] (
        * @param stopGracefully if true, stops gracefully by waiting for the 
processing of all
        *                       received data to be completed
        */
    -  def stop(stopSparkContext: Boolean, stopGracefully: Boolean): Unit = 
synchronized {
    -    try {
    -      state match {
    -        case INITIALIZED =>
    -          logWarning("StreamingContext has not been started yet")
    -        case STOPPED =>
    -          logWarning("StreamingContext has already been stopped")
    -        case ACTIVE =>
    -          scheduler.stop(stopGracefully)
    -          // Removing the streamingSource to de-register the metrics on 
stop()
    -          env.metricsSystem.removeSource(streamingSource)
    -          uiTab.foreach(_.detach())
    -          StreamingContext.setActiveContext(null)
    -          waiter.notifyStop()
    -          if (shutdownHookRef != null) {
    -            ShutdownHookManager.removeShutdownHook(shutdownHookRef)
    -          }
    -          logInfo("StreamingContext stopped successfully")
    +  def stop(stopSparkContext: Boolean, stopGracefully: Boolean): Unit = {
    +    var shutdownHookRefToRemove: AnyRef = null
    +    synchronized {
    +      try {
    +        state match {
    +          case INITIALIZED =>
    +            logWarning("StreamingContext has not been started yet")
    +          case STOPPED =>
    +            logWarning("StreamingContext has already been stopped")
    +          case ACTIVE =>
    +            scheduler.stop(stopGracefully)
    +            // Removing the streamingSource to de-register the metrics on 
stop()
    +            env.metricsSystem.removeSource(streamingSource)
    +            uiTab.foreach(_.detach())
    +            StreamingContext.setActiveContext(null)
    +            waiter.notifyStop()
    +            if (shutdownHookRef != null) {
    +              shutdownHookRefToRemove = shutdownHookRef
    +              shutdownHookRef = null
    +            }
    +            logInfo("StreamingContext stopped successfully")
    +        }
    +        // Even if we have already stopped, we still need to attempt to 
stop the SparkContext
    +        // because a user might stop(stopSparkContext = false) and then 
call
    +        // stop(stopSparkContext = true).
    +        if (stopSparkContext) sc.stop()
    +      } finally {
    +        // The state should always be Stopped after calling `stop()`, even 
if we haven't started yet
    +        state = STOPPED
           }
    -      // Even if we have already stopped, we still need to attempt to stop 
the SparkContext because
    -      // a user might stop(stopSparkContext = false) and then call 
stop(stopSparkContext = true).
    -      if (stopSparkContext) sc.stop()
    -    } finally {
    -      // The state should always be Stopped after calling `stop()`, even 
if we haven't started yet
    -      state = STOPPED
    +    }
    +    if (shutdownHookRefToRemove != null) {
    --- End diff --
    
    should this be inside a finally {}? what if, say sc.stop() throws? wouldn't 
this leak the shutdownhookreftoremove?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to