-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23020][core] Fix another race in the in-process launcher test. #20462
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 1 commit
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 |
|---|---|---|
|
|
@@ -112,7 +112,7 @@ void monitorChild() { | |
| } | ||
| } | ||
|
|
||
| disconnect(); | ||
| dispose(); | ||
|
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. Can we add more document to
Contributor
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.
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. Sorry I'm still not able to figure out what's the difference between them after reading the doc, do you mind leave a short description here? thanks!
Contributor
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. I updated the documentation for dispose. |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,7 @@ synchronized void start(String appName, Method main, String[] args) { | |
| setState(State.FAILED); | ||
| } | ||
|
|
||
| disconnect(); | ||
| dispose(); | ||
|
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. If we call
Contributor
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. The order in which the connection is closed.
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. ah i see |
||
| }); | ||
|
|
||
| app.setName(String.format(THREAD_NAME_FMT, THREAD_IDS.incrementAndGet(), appName)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,6 +238,7 @@ public void run() { | |
| }; | ||
| ServerConnection clientConnection = new ServerConnection(client, timeout); | ||
| Thread clientThread = factory.newThread(clientConnection); | ||
| clientConnection.setConnectionThread(clientThread); | ||
| synchronized (clients) { | ||
| clients.add(clientConnection); | ||
| } | ||
|
|
@@ -290,17 +291,15 @@ class ServerConnection extends LauncherConnection { | |
|
|
||
| private TimerTask timeout; | ||
| private volatile Thread connectionThread; | ||
| volatile AbstractAppHandle handle; | ||
| private volatile AbstractAppHandle handle; | ||
|
|
||
| ServerConnection(Socket socket, TimerTask timeout) throws IOException { | ||
| super(socket); | ||
| this.timeout = timeout; | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| this.connectionThread = Thread.currentThread(); | ||
| super.run(); | ||
| void setConnectionThread(Thread t) { | ||
| this.connectionThread = t; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -363,17 +362,28 @@ public void close() throws IOException { | |
| /** | ||
| * Close the connection and wait for any buffered data to be processed before returning. | ||
|
||
| * This ensures any changes reported by the child application take effect. | ||
| * | ||
| * This method allows a short period for the connection thread to finish by itself (same amount | ||
| * of time as the connection timeout, which is configurable). This should be fine for | ||
| * well-behaved applications, where they close the connection when the app handle detects the | ||
| * app has finished. | ||
| * | ||
| * In case the connection is not closed within the grace period, this method forcefully closes | ||
| * it and any subsequent data that may arrive will be ignored. | ||
| */ | ||
| public void closeAndWait() throws IOException { | ||
| close(); | ||
|
|
||
| public void waitForClose() throws IOException { | ||
| Thread connThread = this.connectionThread; | ||
| if (Thread.currentThread() != connThread) { | ||
| try { | ||
| connThread.join(); | ||
| connThread.join(getConnectionTimeout()); | ||
| } catch (InterruptedException ie) { | ||
| // Ignore. | ||
| } | ||
|
|
||
| if (connThread.isAlive()) { | ||
| LOG.log(Level.WARNING, "Timed out waiting for child connection to close."); | ||
| close(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
why remove
synchronizedhere?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.
I should add this one back.