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-70531] Apply timeout on WebSocket write operations (and simplify AbstractByteBufferCommandTransport) #621

Merged
merged 7 commits into from Feb 3, 2023
15 changes: 12 additions & 3 deletions src/main/java/hudson/remoting/Engine.java
Expand Up @@ -648,9 +648,18 @@ class Transport extends AbstractByteBufferCommandTransport {
}
@Override
protected void write(ByteBuffer header, ByteBuffer data) throws IOException {
LOGGER.finest(() -> "sending message of length + " + ChunkHeader.length(ChunkHeader.peek(header)));
session.getBasicRemote().sendBinary(header, false);
session.getBasicRemote().sendBinary(data, true);
LOGGER.finest(() -> "sending message of length " + ChunkHeader.length(ChunkHeader.peek(header)));
// RemoteEndpoint.Async seems to lack isLast overloads
// adapted from https://stackoverflow.com/a/42170003/12916
ByteBuffer headerAndData = ByteBuffer.allocate(header.remaining() + data.remaining());
jglick marked this conversation as resolved.
Show resolved Hide resolved
headerAndData.put(header.duplicate());
headerAndData.put(data.duplicate());
headerAndData.rewind();
try {
session.getAsyncRemote().sendBinary(headerAndData).get(5, TimeUnit.MINUTES);
} catch (Exception x) {
throw new IOException(x);
}
}

@Override
Expand Down