Skip to content
Snippets Groups Projects
Commit be317d4a authored by Jakob Odersky's avatar Jakob Odersky Committed by Reynold Xin
Browse files

[SPARK-10001][CORE] Don't short-circuit actions in signal handlers

## What changes were proposed in this pull request?
The current signal handlers have a subtle bug that stops evaluating registered actions as soon as one of them returns true, this is because `forall` is short-circuited.
This PR adds a strict mapping stage before evaluating returned result.
There are no known occurrences of the bug and this is a preemptive fix.

## How was this patch tested?
As with the original introduction of signal handlers, this was tested manually (unit testing with signals is not straightforward).

Author: Jakob Odersky <jakob@odersky.com>

Closes #12745 from jodersky/SPARK-10001-hotfix.
parent ae4e3def
No related branches found
No related tags found
No related merge requests found
...@@ -92,9 +92,11 @@ private[spark] object SignalUtils extends Logging { ...@@ -92,9 +92,11 @@ private[spark] object SignalUtils extends Logging {
// register old handler, will receive incoming signals while this handler is running // register old handler, will receive incoming signals while this handler is running
Signal.handle(signal, prevHandler) Signal.handle(signal, prevHandler)
// run all actions, escalate to parent handler if no action catches the signal // Run all actions, escalate to parent handler if no action catches the signal
// (i.e. all actions return false) // (i.e. all actions return false). Note that calling `map` is to ensure that
val escalate = actions.asScala.forall { action => !action() } // all actions are run, `forall` is short-circuited and will stop evaluating
// after reaching a first false predicate.
val escalate = actions.asScala.map(action => action()).forall(_ == false)
if (escalate) { if (escalate) {
prevHandler.handle(sig) prevHandler.handle(sig)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment