Skip to content

Commit

Permalink
[SPARK-21991][LAUNCHER] Fix race condition in LauncherServer#acceptCo…
Browse files Browse the repository at this point in the history
…nnections

## 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 <andrea.zito@u-hopper.com>

Closes #19217 from nivox/SPARK-21991.

(cherry picked from commit 6ea8a56)
  • Loading branch information
Andrea zito authored and Marcelo Vanzin committed Oct 25, 2017
1 parent a96fbd8 commit 8e71b19
Showing 1 changed file with 13 additions and 13 deletions.
Expand Up @@ -237,20 +237,20 @@ public void run() {
};
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) {
Expand Down

0 comments on commit 8e71b19

Please sign in to comment.