-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-21991][LAUNCHER] Fix race condition in LauncherServer#acceptConnections #19217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -232,20 +232,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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are now adding to
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding the connection to This situation is really unlikely but still a possibility. Changing the order of operation shouldn't affect any logic since the |
||
| } | ||
|
|
||
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 on not calling |
||
| } else { | ||
| timeout.run(); | ||
| } | ||
|
|
||
| clientThread.start(); | ||
| } | ||
| } catch (IOException ioe) { | ||
| if (running) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're no longer synchronizing on the
timeouthere, but I didn't see anywhere else synchronizing on it either (includingServerConnection). Given it doesn't escape this method, I'm not sure how multiple threads could ever accesstimeoutat once, so it makes sense to remove this synchronizationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was exactly my reasoning. I couldn't find any reason why the synchronisation was needed. The removal was only a means to make the code simpler removing the cognitive cost suggested by the presence of a synchronise keyword. The actual fix doesn't depend on it.