diff options
author | zsxwing <zsxwing@gmail.com> | 2014-10-29 14:42:50 -0700 |
---|---|---|
committer | Reynold Xin <rxin@databricks.com> | 2014-10-29 14:43:48 -0700 |
commit | abdb90bd7ef1f9d84d63b001b7a305c577b8e0f2 (patch) | |
tree | 14695c0994144ba01a143d3f8029aa4ece9c02e1 /core/src/main | |
parent | f0c571760040c998d83ad87d08e104b38bfc19f7 (diff) | |
download | spark-abdb90bd7ef1f9d84d63b001b7a305c577b8e0f2.tar.gz spark-abdb90bd7ef1f9d84d63b001b7a305c577b8e0f2.tar.bz2 spark-abdb90bd7ef1f9d84d63b001b7a305c577b8e0f2.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'
(cherry picked from commit e7fd80413d531e23b6c4def0ee32e52a39da36fa)
Signed-off-by: Reynold Xin <rxin@databricks.com>
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/scala/org/apache/spark/FutureAction.scala | 6 |
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 1e4dec86a0..3bbf1aab19 100644 --- a/core/src/main/scala/org/apache/spark/FutureAction.scala +++ b/core/src/main/scala/org/apache/spark/FutureAction.scala @@ -190,7 +190,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 |