Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"};

Expand Down Expand Up @@ -165,6 +168,18 @@ private static void configProxy(Properties conf) {
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);
}
Comment on lines +172 to +181
}
}

public static ConsoleProxyServerFactory getHttpServerFactory() {
Expand Down Expand Up @@ -379,7 +394,7 @@ public static void start(Properties conf) {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
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;
Expand All @@ -45,6 +45,13 @@ public ConsoleProxyGCThread(Map<String, ConsoleProxyClient> connMap, Set<String>
this.removedSessionsSet = removedSet;
}

private int getMaxSessionIdleSeconds() {
if (ConsoleProxy.sessionTimeoutMillis <= 0) {
return DEFAULT_MAX_SESSION_IDLE_SECONDS;
}
return ConsoleProxy.sessionTimeoutMillis / 1000;
}

Comment on lines +48 to +54
private void cleanupLogging() {
if (lastLogScan != 0 && System.currentTimeMillis() - lastLogScan < 3600000)
return;
Expand Down Expand Up @@ -92,7 +99,7 @@ public void run() {
}

long seconds_unused = (System.currentTimeMillis() - client.getClientLastFrontEndActivityTime()) / 1000;
if (seconds_unused < MAX_SESSION_IDLE_SECONDS) {
if (seconds_unused < getMaxSessionIdleSeconds()) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public void onConnect(final Session session) throws IOException, InterruptedExce
}

try {
session.setIdleTimeout(ConsoleProxy.sessionTimeoutMillis);
logger.debug("Set noVNC WebSocket idle timeout to {} ms for session UUID: {}.",
ConsoleProxy.sessionTimeoutMillis, sessionUuid);

Comment on lines 127 to +131
ConsoleProxyClientParam param = new ConsoleProxyClientParam();
param.setClientHostAddress(host);
param.setClientHostPort(port);
Expand Down Expand Up @@ -185,12 +189,21 @@ public void onClose(Session session, int statusCode, String reason) throws IOExc

@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);
}
}
}
Loading