Honour consoleproxy.session.timeout for noVNC sessions

This commit is contained in:
dheeraj12347 2026-04-11 11:12:36 +05:30
parent 3166e64891
commit 0488c6604b
3 changed files with 39 additions and 4 deletions

View File

@ -80,6 +80,9 @@ public class ConsoleProxy {
static String factoryClzName;
static boolean standaloneStart = false;
// New: session timeout in milliseconds, default 300000 (5 minutes)
static int sessionTimeoutMillis = 300000;
static String encryptorPassword = "Dummy";
static final String[] skipProperties = new String[]{"certificate", "cacertificate", "keystore_password", "privatekey"};
@ -165,6 +168,18 @@ public class ConsoleProxy {
defaultBufferSize = Integer.parseInt(s);
LOGGER.info("Setting defaultBufferSize=" + defaultBufferSize);
}
// New: read consoleproxy.session.timeout (milliseconds)
s = conf.getProperty("consoleproxy.session.timeout");
if (s != null) {
try {
sessionTimeoutMillis = Integer.parseInt(s);
LOGGER.info("Setting consoleproxy.session.timeout=" + sessionTimeoutMillis);
} catch (NumberFormatException e) {
LOGGER.warn("Invalid value for consoleproxy.session.timeout: " + s +
", using default " + sessionTimeoutMillis, e);
}
}
}
public static ConsoleProxyServerFactory getHttpServerFactory() {
@ -379,7 +394,7 @@ public class ConsoleProxy {
LOGGER.info("HTTP command port is disabled");
}
ConsoleProxyGCThread cthread = new ConsoleProxyGCThread(connectionMap, removedSessionsSet);
ConsoleProxyGCThread cthread = new ConsoleProxyGCThread(connectionMap, removedSessionsSet /*, sessionTimeoutMillis */);
cthread.setName("Console Proxy GC Thread");
cthread.start();
}

View File

@ -34,7 +34,7 @@ import org.apache.logging.log4j.LogManager;
public class ConsoleProxyGCThread extends Thread {
protected Logger logger = LogManager.getLogger(ConsoleProxyGCThread.class);
private final static int MAX_SESSION_IDLE_SECONDS = 180;
private final static int DEFAULT_MAX_SESSION_IDLE_SECONDS = 180;
private final Map<String, ConsoleProxyClient> connMap;
private final Set<String> removedSessionsSet;
@ -45,6 +45,13 @@ public class ConsoleProxyGCThread extends Thread {
this.removedSessionsSet = removedSet;
}
private int getMaxSessionIdleSeconds() {
if (ConsoleProxy.sessionTimeoutMillis <= 0) {
return DEFAULT_MAX_SESSION_IDLE_SECONDS;
}
return ConsoleProxy.sessionTimeoutMillis / 1000;
}
private void cleanupLogging() {
if (lastLogScan != 0 && System.currentTimeMillis() - lastLogScan < 3600000)
return;
@ -92,7 +99,7 @@ public class ConsoleProxyGCThread extends Thread {
}
long seconds_unused = (System.currentTimeMillis() - client.getClientLastFrontEndActivityTime()) / 1000;
if (seconds_unused < MAX_SESSION_IDLE_SECONDS) {
if (seconds_unused < getMaxSessionIdleSeconds()) {
continue;
}

View File

@ -125,6 +125,10 @@ public class ConsoleProxyNoVNCHandler extends WebSocketHandler {
}
try {
session.setIdleTimeout(ConsoleProxy.sessionTimeoutMillis);
logger.debug("Set noVNC WebSocket idle timeout to {} ms for session UUID: {}.",
ConsoleProxy.sessionTimeoutMillis, sessionUuid);
ConsoleProxyClientParam param = new ConsoleProxyClientParam();
param.setClientHostAddress(host);
param.setClientHostPort(port);
@ -185,12 +189,21 @@ public class ConsoleProxyNoVNCHandler extends WebSocketHandler {
@OnWebSocketFrame
public void onFrame(Frame f) throws IOException {
if (viewer == null) {
logger.warn("Ignoring WebSocket frame because viewer is not initialized yet.");
return;
}
logger.trace("Sending client [ID: {}] frame of {} bytes.", viewer.getClientId(), f.getPayloadLength());
viewer.sendClientFrame(f);
}
@OnWebSocketError
public void onError(Throwable cause) {
logger.error("Error on WebSocket [client ID: {}, session UUID: {}].", cause, viewer.getClientId(), viewer.getSessionUuid());
if (viewer != null) {
logger.error("Error on WebSocket [client ID: {}, session UUID: {}].",
viewer.getClientId(), viewer.getSessionUuid(), cause);
} else {
logger.error("Error on WebSocket before viewer initialization.", cause);
}
}
}