aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorzsxwing <zsxwing@gmail.com>2014-10-29 14:42:50 -0700
committerReynold Xin <rxin@databricks.com>2014-10-29 14:42:50 -0700
commite7fd80413d531e23b6c4def0ee32e52a39da36fa (patch)
treeb9610ad8f97943d4337c344756d15f315a200284 /core
parent1df05a40ebf3493b0aff46d18c0f30d2d5256c7b (diff)
downloadspark-e7fd80413d531e23b6c4def0ee32e52a39da36fa.tar.gz
spark-e7fd80413d531e23b6c4def0ee32e52a39da36fa.tar.bz2
spark-e7fd80413d531e23b6c4def0ee32e52a39da36fa.zip
[SPARK-4097] Fix the race condition of 'thread'
There is a chance that `thread` is null when calling `thread.interrupt()`. ```Scala override def cancel(): Unit = this.synchronized { _cancelled = true if (thread != null) { thread.interrupt() } } ``` Should put `thread = null` into a `synchronized` block to fix the race condition. Author: zsxwing <zsxwing@gmail.com> Closes #2957 from zsxwing/SPARK-4097 and squashes the following commits: edf0aee [zsxwing] Add comments to explain the lock c5cfeca [zsxwing] Fix the race condition of 'thread'
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/org/apache/spark/FutureAction.scala6
1 files changed, 5 insertions, 1 deletions
diff --git a/core/src/main/scala/org/apache/spark/FutureAction.scala b/core/src/main/scala/org/apache/spark/FutureAction.scala
index d5c8f9d76c..e97a7375a2 100644
--- a/core/src/main/scala/org/apache/spark/FutureAction.scala
+++ b/core/src/main/scala/org/apache/spark/FutureAction.scala
@@ -210,7 +210,11 @@ class ComplexFutureAction[T] extends FutureAction[T] {
} catch {
case e: Exception => p.failure(e)
} finally {
- thread = null
+ // This lock guarantees when calling `thread.interrupt()` in `cancel`,
+ // thread won't be set to null.
+ ComplexFutureAction.this.synchronized {
+ thread = null
+ }
}
}
this