Repository: spark
Updated Branches:
  refs/heads/branch-2.1 5a4072b2c -> dc09714a0


[SPARK-21991][LAUNCHER] Fix race condition in LauncherServer#acceptConnections

## What changes were proposed in this pull request?
This patch changes the order in which _acceptConnections_ starts the client 
thread and schedules the client timeout action ensuring that the latter has 
been scheduled before the former get a chance to cancel it.

## How was this patch tested?
Due to the non-deterministic nature of the patch I wasn't able to add a new 
test for this issue.

Author: Andrea zito <[email protected]>

Closes #19217 from nivox/SPARK-21991.

(cherry picked from commit 6ea8a56ca26a7e02e6574f5f763bb91059119a80)
Signed-off-by: Marcelo Vanzin <[email protected]>


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

Branch: refs/heads/branch-2.1
Commit: dc09714a014f8683e8c2a4e75849ea21efb63923
Parents: 5a4072b
Author: Andrea zito <[email protected]>
Authored: Wed Oct 25 10:10:24 2017 -0700
Committer: Marcelo Vanzin <[email protected]>
Committed: Wed Oct 25 10:10:49 2017 -0700

----------------------------------------------------------------------
 .../apache/spark/launcher/LauncherServer.java   | 26 ++++++++++----------
 1 file changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/dc09714a/launcher/src/main/java/org/apache/spark/launcher/LauncherServer.java
----------------------------------------------------------------------
diff --git 
a/launcher/src/main/java/org/apache/spark/launcher/LauncherServer.java 
b/launcher/src/main/java/org/apache/spark/launcher/LauncherServer.java
index ae43f56..970819f 100644
--- a/launcher/src/main/java/org/apache/spark/launcher/LauncherServer.java
+++ b/launcher/src/main/java/org/apache/spark/launcher/LauncherServer.java
@@ -237,20 +237,20 @@ class LauncherServer implements Closeable {
         };
         ServerConnection clientConnection = new ServerConnection(client, 
timeout);
         Thread clientThread = factory.newThread(clientConnection);
-        synchronized (timeout) {
-          clientThread.start();
-          synchronized (clients) {
-            clients.add(clientConnection);
-          }
-          long timeoutMs = getConnectionTimeout();
-          // 0 is used for testing to avoid issues with clock resolution / 
thread scheduling,
-          // and force an immediate timeout.
-          if (timeoutMs > 0) {
-            timeoutTimer.schedule(timeout, getConnectionTimeout());
-          } else {
-            timeout.run();
-          }
+        synchronized (clients) {
+          clients.add(clientConnection);
+        }
+        
+        long timeoutMs = getConnectionTimeout();
+        // 0 is used for testing to avoid issues with clock resolution / 
thread scheduling,
+        // and force an immediate timeout.
+        if (timeoutMs > 0) {
+          timeoutTimer.schedule(timeout, timeoutMs);
+        } else {
+          timeout.run();
         }
+            
+        clientThread.start();
       }
     } catch (IOException ioe) {
       if (running) {


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

Reply via email to