diff options
author | Sean Owen <sowen@cloudera.com> | 2015-01-28 12:44:35 -0800 |
---|---|---|
committer | Patrick Wendell <patrick@databricks.com> | 2015-01-28 12:44:35 -0800 |
commit | 9b18009b835c784e9716594713f3d27d8e48d86c (patch) | |
tree | abe527ebb7ebbec792767eb8a3cefb90a9f267b5 /core/src | |
parent | e902dc443dcc20f904e628b79b430b456cb330e4 (diff) | |
download | spark-9b18009b835c784e9716594713f3d27d8e48d86c.tar.gz spark-9b18009b835c784e9716594713f3d27d8e48d86c.tar.bz2 spark-9b18009b835c784e9716594713f3d27d8e48d86c.zip |
SPARK-1934 [CORE] "this" reference escape to "selectorThread" during construction in ConnectionManager
This change reshuffles the order of initialization in `ConnectionManager` so that the last thing that happens is running `selectorThread`, which invokes a method that relies on object state in `ConnectionManager`
zsxwing also reported a similar problem in `BlockManager` in the JIRA, but I can't find a similar pattern there. Maybe it was subsequently fixed?
Author: Sean Owen <sowen@cloudera.com>
Closes #4225 from srowen/SPARK-1934 and squashes the following commits:
c4dec3b [Sean Owen] Init all object state in ConnectionManager constructor before starting thread in constructor that accesses object's state
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/scala/org/apache/spark/network/nio/ConnectionManager.scala | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/core/src/main/scala/org/apache/spark/network/nio/ConnectionManager.scala b/core/src/main/scala/org/apache/spark/network/nio/ConnectionManager.scala index 03c4137ca0..ee22c6656e 100644 --- a/core/src/main/scala/org/apache/spark/network/nio/ConnectionManager.scala +++ b/core/src/main/scala/org/apache/spark/network/nio/ConnectionManager.scala @@ -184,14 +184,16 @@ private[nio] class ConnectionManager( // to be able to track asynchronous messages private val idCount: AtomicInteger = new AtomicInteger(1) + private val writeRunnableStarted: HashSet[SelectionKey] = new HashSet[SelectionKey]() + private val readRunnableStarted: HashSet[SelectionKey] = new HashSet[SelectionKey]() + private val selectorThread = new Thread("connection-manager-thread") { override def run() = ConnectionManager.this.run() } selectorThread.setDaemon(true) + // start this thread last, since it invokes run(), which accesses members above selectorThread.start() - private val writeRunnableStarted: HashSet[SelectionKey] = new HashSet[SelectionKey]() - private def triggerWrite(key: SelectionKey) { val conn = connectionsByKey.getOrElse(key, null) if (conn == null) return @@ -232,7 +234,6 @@ private[nio] class ConnectionManager( } ) } - private val readRunnableStarted: HashSet[SelectionKey] = new HashSet[SelectionKey]() private def triggerRead(key: SelectionKey) { val conn = connectionsByKey.getOrElse(key, null) |