Skip to content

Commit 4f2c290

Browse files
committed
console proxy: fix noVNC handshake busy-spin causing intermittent console connect timeouts
waitForNoVNCReply() was an unbounded CPU busy-spin waiting for the browser's handshake reply. Under concurrent console load this could starve the Jetty I/O thread delivering the reply, stalling the handshake until noVNC's client-side timeout gave up and reloaded the page. Replace the spin with a wait/notify on the existing lock, bounded by a timeout that logs a warning instead of hanging silently.
1 parent 1805dde commit 4f2c290

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

  • services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc

‎services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/NoVncClient.java‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,25 @@ public ByteBuffer handshakeProtocolVersion() {
413413
return verStr;
414414
}
415415

416+
protected static final long WAIT_FOR_NOVNC_TIMEOUT_MS = 30000;
417+
416418
public void waitForNoVNCReply() {
417-
int cycles = 0;
418-
while (isWaitForNoVnc()) {
419-
cycles++;
420-
}
421-
if (logger.isDebugEnabled()) {
422-
logger.debug(String.format("Waited %d cycles for NoVnc", cycles));
419+
long start = System.currentTimeMillis();
420+
synchronized (lock) {
421+
while (waitForNoVnc) {
422+
long remaining = WAIT_FOR_NOVNC_TIMEOUT_MS - (System.currentTimeMillis() - start);
423+
if (remaining <= 0) {
424+
logger.warn("Timed out after {} ms waiting for a reply from the noVNC client during handshake", WAIT_FOR_NOVNC_TIMEOUT_MS);
425+
break;
426+
}
427+
try {
428+
lock.wait(remaining);
429+
} catch (InterruptedException e) {
430+
Thread.currentThread().interrupt();
431+
logger.warn("Interrupted while waiting for a reply from the noVNC client during handshake", e);
432+
break;
433+
}
434+
}
423435
}
424436
}
425437

@@ -468,6 +480,7 @@ public int handshakeSecurityType() {
468480
public void setWaitForNoVnc(boolean val) {
469481
synchronized (lock) {
470482
this.waitForNoVnc = val;
483+
lock.notifyAll();
471484
}
472485
}
473486

0 commit comments

Comments
 (0)