Skip to content

Commit 1a16c79

Browse files
authored
Merge pull request #4461 from kubernetes-client/copilot/fix-websocket-flush-delay
Reduce WebSocket flush wait from 100ms to 1ms
2 parents f44c0ea + 913b334 commit 1a16c79

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ private class WebSocketOutputStream extends OutputStream {
244244

245245
private static final int WAIT_MILLIS = 10;
246246

247+
private static final int FLUSH_WAIT_MILLIS = 1;
248+
249+
private static final int MAX_FLUSH_ITERATIONS = MAX_WAIT_MILLIS / FLUSH_WAIT_MILLIS;
250+
247251
private final byte stream;
248252

249253
public WebSocketOutputStream(int stream) {
@@ -272,11 +276,11 @@ public void flush() throws IOException {
272276
int i = 0;
273277
while (WebSocketStreamHandler.this.socket.queueSize() > 0) {
274278
try {
275-
Thread.sleep(100);
279+
Thread.sleep(FLUSH_WAIT_MILLIS);
276280
} catch (InterruptedException ex) {
277281
}
278282
// Wait a maximum of 10 seconds.
279-
if (i++ > 100) {
283+
if (i++ > MAX_FLUSH_ITERATIONS) {
280284
throw new IOException("Timed out waiting for web-socket to flush.");
281285
}
282286
}

0 commit comments

Comments
 (0)