Skip to content

Commit 9278fb3

Browse files
Keep lock-free fast path in WebSocketOutputStream.write
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
1 parent 70fc7de commit 9278fb3

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎util/src/main/java/io/kubernetes/client/util/WebSocketStreamHandler.java‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,17 @@ public void write(byte[] b) throws IOException {
312312

313313
@Override
314314
public void write(byte[] b, int offset, int length) throws IOException {
315-
synchronized (WebSocketStreamHandler.this) {
316-
// wait for the websocket to be opened, failing fast if the handler is closed
317-
// (e.g. because the connection failed) before or while waiting.
318-
while (WebSocketStreamHandler.this.socket == null) {
319-
if (state == State.CLOSED) throw new IllegalStateException();
320-
try {
321-
WebSocketStreamHandler.this.wait();
322-
} catch (InterruptedException e) {
323-
throw new InterruptedIOException();
315+
if (WebSocketStreamHandler.this.socket == null) {
316+
synchronized (WebSocketStreamHandler.this) {
317+
// wait for the websocket to be opened, failing fast if the handler is closed
318+
// (e.g. because the connection failed) before or while waiting.
319+
while (WebSocketStreamHandler.this.socket == null) {
320+
if (state == State.CLOSED) throw new IllegalStateException();
321+
try {
322+
WebSocketStreamHandler.this.wait();
323+
} catch (InterruptedException e) {
324+
throw new InterruptedIOException();
325+
}
324326
}
325327
}
326328
}

0 commit comments

Comments
 (0)