-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-12049] [CORE] User JVM shutdown hook can cause deadlock at shutdown #10042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,7 +206,7 @@ private[spark] object ShutdownHookManager extends Logging { | |
| private [util] class SparkShutdownHookManager { | ||
|
|
||
| private val hooks = new PriorityQueue[SparkShutdownHook]() | ||
| private var shuttingDown = false | ||
| @volatile private var shuttingDown = false | ||
|
|
||
| /** | ||
| * Install a hook to run at shutdown and run all registered hooks in order. Hadoop 1.x does not | ||
|
|
@@ -232,22 +232,23 @@ private [util] class SparkShutdownHookManager { | |
| } | ||
| } | ||
|
|
||
| def runAll(): Unit = synchronized { | ||
| def runAll(): Unit = { | ||
| shuttingDown = true | ||
| while (!hooks.isEmpty()) { | ||
| Try(Utils.logUncaughtExceptions(hooks.poll().run())) | ||
| var nextHook: SparkShutdownHook = null | ||
| while ({nextHook = hooks synchronized { hooks.poll() }; nextHook != null}) { | ||
| Try(Utils.logUncaughtExceptions(nextHook.run())) | ||
| } | ||
| } | ||
|
|
||
| def add(priority: Int, hook: () => Unit): AnyRef = synchronized { | ||
| def add(priority: Int, hook: () => Unit): AnyRef = { | ||
| checkState() | ||
| val hookRef = new SparkShutdownHook(priority, hook) | ||
| hooks.add(hookRef) | ||
| hooks synchronized { hooks.add(hookRef) } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, technically, this is not really thread-safe anymore. You can have this order of things: T1: in add(), passes Granted, that's very unlikely. I think if you move the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, you got me. That really has to be tightened up. Will address these shortly. |
||
| hookRef | ||
| } | ||
|
|
||
| def remove(ref: AnyRef): Boolean = synchronized { | ||
| hooks.remove(ref) | ||
| def remove(ref: AnyRef): Boolean = { | ||
| hooks synchronized { hooks.remove(ref) } | ||
| } | ||
|
|
||
| private def checkState(): Unit = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we generally use
hooks.synchronized.