Repository: spark
Updated Branches:
  refs/heads/master 1df05a40e -> e7fd80413


[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 <[email protected]>

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'


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/e7fd8041
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/e7fd8041
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/e7fd8041

Branch: refs/heads/master
Commit: e7fd80413d531e23b6c4def0ee32e52a39da36fa
Parents: 1df05a4
Author: zsxwing <[email protected]>
Authored: Wed Oct 29 14:42:50 2014 -0700
Committer: Reynold Xin <[email protected]>
Committed: Wed Oct 29 14:42:50 2014 -0700

----------------------------------------------------------------------
 core/src/main/scala/org/apache/spark/FutureAction.scala | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/e7fd8041/core/src/main/scala/org/apache/spark/FutureAction.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/org/apache/spark/FutureAction.scala 
b/core/src/main/scala/org/apache/spark/FutureAction.scala
index d5c8f9d..e97a737 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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to