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

[JENKINS-69890] Prevent deadlock on websocket agents #595

Merged
merged 5 commits into from
Oct 26, 2022
Merged
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
11 changes: 9 additions & 2 deletions src/main/java/hudson/remoting/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -623,15 +623,22 @@ private void onMessage(ByteBuffer message) {
}
}
@Override
@SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE",
justification = "We want the transport.terminate method to run asynchronously and don't want to wait for its status.")
public void onClose(Session session, CloseReason closeReason) {
LOGGER.fine(() -> "onClose: " + closeReason);
transport.terminate(new ChannelClosedException(ch.get(), null));
// making this call async to avoid potential deadlocks when some thread is holding a lock on the
// channel object while this thread is trying to acquire it to call Transport#terminate
ch.get().executor.submit(() -> transport.terminate(new ChannelClosedException(ch.get(), null)));
Comment on lines +630 to +632
Copy link
Member

@Vlatombe Vlatombe Oct 19, 2022

Choose a reason for hiding this comment

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

I suspect a similar change would be needed in onError method if it works.

Copy link
Member

Choose a reason for hiding this comment

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

👍

I just added it as well.

}
@Override
@SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE",
justification = "We want the transport.terminate method to run asynchronously and don't want to wait for its status.")
public void onError(Session session, Throwable x) {
// TODO or would events.error(x) be better?
LOGGER.log(Level.FINE, null, x);
transport.terminate(new ChannelClosedException(ch.get(), x));
// as above
ch.get().executor.submit(() -> transport.terminate(new ChannelClosedException(ch.get(), x)));
}

class Transport extends AbstractByteBufferCommandTransport {
Expand Down