Skip to content
Snippets Groups Projects
Commit e7fd8041 authored by zsxwing's avatar zsxwing Committed by Reynold Xin
Browse files

[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'
parent 1df05a40
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
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