Skip to content
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

[SPARK-23785][LAUNCHER] LauncherBackend doesn't check state of connection before setting state #20893

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ private[spark] abstract class LauncherBackend {
}

def setAppId(appId: String): Unit = {
if (connection != null) {
if (connection != null && isConnected) {
connection.send(new SetAppId(appId))
}
}

def setState(state: SparkAppHandle.State): Unit = {
if (connection != null && lastState != state) {
if (connection != null && isConnected && lastState != state) {
connection.send(new SetState(state))
lastState = state
}
Expand Down Expand Up @@ -114,10 +114,10 @@ private[spark] abstract class LauncherBackend {

override def close(): Unit = {
try {
_isConnected = false
super.close()
} finally {
onDisconnected()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I searched the code and seems this is a no-op?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_isConnected is used in def isConnected(). Moving it from the finally block to before the call to super.close() avoids a race condition where a client tries to write to the connection after it has been closed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know your meaning, but I'm not referring to isConnected, I mean onDisconnected seems not doing anything on Spark side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not quite directly related, but this should means it is safe to move _isConnected = false to before onDisconnected().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, your right, it doesn't look like onDisconnected is being used anywhere, but its marked as protected so I guess its meant to be used by a sub-class (although no sub-class uses it).

So agree, this change should be safe, it doesn't change the semantics of any use of onDisconnected

_isConnected = false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,26 @@ public void testStreamFiltering() throws Exception {
}
}

@Test
public void testAppHandleDisconnect() throws Exception {
LauncherServer server = LauncherServer.getOrCreateServer();
ChildProcAppHandle handle = new ChildProcAppHandle(server);
String secret = server.registerHandle(handle);

TestClient client = null;
try {
Socket s = new Socket(InetAddress.getLoopbackAddress(), server.getPort());
client = new TestClient(s);
client.send(new Hello(secret, "1.4.0"));
handle.disconnect();
waitForError(client, secret);
} finally {
handle.kill();
close(client);
client.clientThread.join();
}
}

private void close(Closeable c) {
if (c != null) {
try {
Expand Down