From 9453345d1e9fcc1ef34834d22e94463b0e05bcd6 Mon Sep 17 00:00:00 2001 From: nvazquez Date: Thu, 23 Jul 2026 23:33:12 -0300 Subject: [PATCH 1/4] Add lock and synchronize allowed sessions --- .../com/cloud/consoleproxy/ConsoleProxy.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java index a25abac981b9..de5834cffcd2 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java @@ -26,7 +26,6 @@ import java.net.InetSocketAddress; import java.net.URISyntaxException; import java.net.URL; -import java.util.HashSet; import java.util.Hashtable; import java.util.Map; import java.util.Properties; @@ -83,8 +82,10 @@ public class ConsoleProxy { static String encryptorPassword = "Dummy"; static final String[] skipProperties = new String[]{"certificate", "cacertificate", "keystore_password", "privatekey"}; - static Set allowedSessions = new HashSet<>(); + static Set allowedSessions = ConcurrentHashMap.newKeySet(); + private static final Object allowedSessionsLock = new Object(); + // Invoked through reflection public static void addAllowedSession(String sessionUuid) { allowedSessions.add(sessionUuid); } @@ -209,13 +210,15 @@ public static ConsoleProxyAuthenticationResult authenticateConsoleAccess(Console } String sessionUuid = param.getSessionUuid(); - if (allowedSessions.contains(sessionUuid)) { - LOGGER.debug("Acquiring the session " + sessionUuid + " not available for future use"); - allowedSessions.remove(sessionUuid); - } else { - LOGGER.info("Session " + sessionUuid + " has already been used, cannot connect"); - authResult.setSuccess(false); - return authResult; + synchronized (allowedSessionsLock) { + if (allowedSessions.contains(sessionUuid)) { + LOGGER.debug("Acquiring the session " + sessionUuid + " not available for future use"); + allowedSessions.remove(sessionUuid); + } else { + LOGGER.info("Session " + sessionUuid + " has already been used, cannot connect"); + authResult.setSuccess(false); + return authResult; + } } String websocketUrl = param.getWebsocketUrl(); From 08a76bad20dd0e6fa219996dc4832ba341e6320f Mon Sep 17 00:00:00 2001 From: nvazquez Date: Thu, 23 Jul 2026 23:47:04 -0300 Subject: [PATCH 2/4] Fix closing connections to VNC ports on console close --- .../com/cloud/consoleproxy/ConsoleProxy.java | 2 +- .../ConsoleProxyNoVNCHandler.java | 16 +++++++++---- .../consoleproxy/ConsoleProxyNoVncClient.java | 3 +++ .../cloud/consoleproxy/vnc/NoVncClient.java | 22 +++++++++++++++++ .../consoleproxy/vnc/network/NioSocket.java | 24 +++++++++++++++++++ .../vnc/network/NioSocketHandler.java | 1 + .../vnc/network/NioSocketHandlerImpl.java | 7 ++++++ 7 files changed, 70 insertions(+), 5 deletions(-) diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java index de5834cffcd2..532c73d2461c 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java @@ -628,7 +628,7 @@ public static ConsoleProxyNoVncClient getNoVncViewer(ConsoleProxyClientParam par } catch (IOException e) { LOGGER.error("Exception while disconnect session of novnc viewer object: " + viewer, e); } - removeViewer(viewer); + viewer.closeClient(); viewer = new ConsoleProxyNoVncClient(session); viewer.initClient(param); connectionMap.put(clientKey, viewer); diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVNCHandler.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVNCHandler.java index a148b988e40d..dba38d5453ce 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVNCHandler.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVNCHandler.java @@ -175,12 +175,20 @@ private boolean checkSessionSourceIp(final Session session, final String sourceI @OnWebSocketClose public void onClose(Session session, int statusCode, String reason) throws IOException, InterruptedException { - String sessionSourceIp = session.getRemoteAddress().getAddress().getHostAddress(); - logger.debug("Closing WebSocket session [source IP: {}, status code: {}].", sessionSourceIp, statusCode); if (viewer != null) { - ConsoleProxy.removeViewer(viewer); + viewer.closeClient(); + } + String sessionSourceIp = getRemoteAddressSafely(session); + logger.debug("WebSocket session [source IP: {}, status code: {}, reason: {}] closed successfully.", sessionSourceIp, statusCode, reason); + } + + private String getRemoteAddressSafely(Session session) { + try { + return session.getRemoteAddress().getAddress().getHostAddress(); + } catch (Exception e) { + logger.debug("Failed to get remote address from WebSocket session", e); + return "unknown"; } - logger.debug("WebSocket session [source IP: {}, status code: {}] closed successfully.", sessionSourceIp, statusCode); } @OnWebSocketFrame diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java index 36dce8b8554c..b844ab1aaa02 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java @@ -374,6 +374,9 @@ public void closeClient() { this.connectionAlive = false; // Clear buffer reference to allow GC when client disconnects this.readBuffer = null; + if (client != null) { + client.close(); + } ConsoleProxy.removeViewer(this); } diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/NoVncClient.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/NoVncClient.java index ca7577d2bfcb..938b810356be 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/NoVncClient.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/NoVncClient.java @@ -129,6 +129,28 @@ public void proxyMsgOverWebSocketConnection(ByteBuffer msg) { } } + public void close() { + if (nioSocketConnection != null) { + nioSocketConnection.close(); + } + if (webSocketReverseProxy != null) { + webSocketReverseProxy.close(); + } + if (socket != null) { + try { + if (is != null) { + is.close(); + } + if (os != null) { + os.close(); + } + socket.close(); + } catch (IOException e) { + logger.debug("Error closing socket: " + e.getMessage(), e); + } + } + } + private void setTunnelSocketStreams() throws IOException { this.is = new DataInputStream(this.socket.getInputStream()); this.os = new DataOutputStream(this.socket.getOutputStream()); diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocket.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocket.java index 4ab88ea9fc72..60ec0f312353 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocket.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocket.java @@ -120,4 +120,28 @@ protected int writeToSocketChannel(ByteBuffer buf, int len) { return 0; } } + + public void close() { + try { + if (socketChannel != null) { + socketChannel.close(); + } + } catch (IOException e) { + logger.debug("Error closing socket channel: " + e.getMessage(), e); + } + try { + if (readSelector != null) { + readSelector.close(); + } + } catch (IOException e) { + logger.debug("Error closing read selector: " + e.getMessage(), e); + } + try { + if (writeSelector != null) { + writeSelector.close(); + } + } catch (IOException e) { + logger.debug("Error closing write selector: " + e.getMessage(), e); + } + } } diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketHandler.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketHandler.java index 757f9c126ec0..02ee2ad7e508 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketHandler.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketHandler.java @@ -41,4 +41,5 @@ public interface NioSocketHandler { void flushWriteBuffer(); void startTLSConnection(NioSocketSSLEngineManager sslEngineManager); boolean isTLSConnection(); + void close(); } diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketHandlerImpl.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketHandlerImpl.java index fc19c36b3edd..0472a338a855 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketHandlerImpl.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketHandlerImpl.java @@ -28,10 +28,12 @@ public class NioSocketHandlerImpl implements NioSocketHandler { private NioSocketInputStream inputStream; private NioSocketOutputStream outputStream; private boolean isTLS = false; + private final NioSocket socket; protected Logger logger = LogManager.getLogger(getClass()); public NioSocketHandlerImpl(NioSocket socket) { + this.socket = socket; this.inputStream = new NioSocketInputStream(ConsoleProxy.defaultBufferSize, socket); this.outputStream = new NioSocketOutputStream(ConsoleProxy.defaultBufferSize, socket); } @@ -109,4 +111,9 @@ public NioSocketInputStream getInputStream() { public NioSocketOutputStream getOutputStream() { return outputStream; } + + @Override + public void close() { + socket.close(); + } } From 54d0d7a971faf46e4815c4542a786e7ed7cbfeee Mon Sep 17 00:00:00 2001 From: nvazquez Date: Mon, 27 Jul 2026 11:17:32 -0300 Subject: [PATCH 3/4] Add reconnection grant window to prevent network connectivity issues after acquiring a session --- .../com/cloud/consoleproxy/ConsoleProxy.java | 61 ++++++++++++++++++- .../consoleproxy/ConsoleProxyGCThread.java | 1 + .../consoleproxy/ConsoleProxyNoVncClient.java | 1 + systemvm/agent/conf/consoleproxy.properties | 1 + 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java index 532c73d2461c..daf1122656fe 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java @@ -85,11 +85,59 @@ public class ConsoleProxy { static Set allowedSessions = ConcurrentHashMap.newKeySet(); private static final Object allowedSessionsLock = new Object(); + private static final Map sessionReconnectGrants = new ConcurrentHashMap<>(); + static int sessionReconnectGraceSeconds = 1; + // Invoked through reflection public static void addAllowedSession(String sessionUuid) { allowedSessions.add(sessionUuid); } + /** + * Grant a short, single-use window to reconnect with the same session UUID in case of a disconnection. + * The grant is bound to the client IP that was using the session so it cannot be redeemed by another client. + * @param sessionUuid session UUID to grant a reconnect window for + * @param clientIp source IP of the client the session was granted to + */ + public static void grantReconnectWindow(String sessionUuid, String clientIp) { + sessionReconnectGrants.put(sessionUuid, new ReconnectGrant(System.currentTimeMillis() + sessionReconnectGraceSeconds * 1000L, clientIp)); + } + + private static boolean consumeReconnectGrant(String sessionUuid, String clientIp) { + ReconnectGrant grant = sessionReconnectGrants.remove(sessionUuid); + if (grant == null || grant.isExpired(System.currentTimeMillis())) { + return false; + } + if (grant.clientIp != null && !grant.clientIp.equals(clientIp)) { + LOGGER.warn("Rejecting reconnect for session " + sessionUuid + " as it was requested from IP " + + clientIp + " but the reconnect window was granted to IP " + grant.clientIp); + return false; + } + return true; + } + + /** + * Drops expired, unclaimed reconnect grants so sessionReconnectGrants doesn't grow unbounded + * when a client never reconnects after a disconnection. Invoked periodically by {@link ConsoleProxyGCThread}. + */ + static void cleanupExpiredReconnectGrants() { + sessionReconnectGrants.entrySet().removeIf(entry -> entry.getValue().isExpired(System.currentTimeMillis())); + } + + private static final class ReconnectGrant { + final long expiryMillis; + final String clientIp; + + ReconnectGrant(long expiryMillis, String clientIp) { + this.expiryMillis = expiryMillis; + this.clientIp = clientIp; + } + + boolean isExpired(long now) { + return now >= expiryMillis; + } + } + private static void configLog4j() { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL configUrl = loader.getResource("/conf/log4j-cloud.xml"); @@ -167,6 +215,12 @@ private static void configProxy(Properties conf) { defaultBufferSize = Integer.parseInt(s); LOGGER.info("Setting defaultBufferSize=" + defaultBufferSize); } + + s = conf.getProperty("consoleproxy.sessionReconnectGraceSeconds"); + if (s != null) { + sessionReconnectGraceSeconds = Integer.parseInt(s); + LOGGER.info("Setting sessionReconnectGraceSeconds=" + sessionReconnectGraceSeconds); + } } public static ConsoleProxyServerFactory getHttpServerFactory() { @@ -211,9 +265,10 @@ public static ConsoleProxyAuthenticationResult authenticateConsoleAccess(Console String sessionUuid = param.getSessionUuid(); synchronized (allowedSessionsLock) { - if (allowedSessions.contains(sessionUuid)) { - LOGGER.debug("Acquiring the session " + sessionUuid + " not available for future use"); - allowedSessions.remove(sessionUuid); + if (allowedSessions.remove(sessionUuid)) { + LOGGER.debug("Acquiring the session " + sessionUuid + " for use"); + } else if (consumeReconnectGrant(sessionUuid, param.getClientIp())) { + LOGGER.info("Reconnecting the session " + sessionUuid + " after a dropped connection"); } else { LOGGER.info("Session " + sessionUuid + " has already been used, cannot connect"); authResult.setSuccess(false); diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyGCThread.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyGCThread.java index 0e8f576cf6db..74d83fb591ff 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyGCThread.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyGCThread.java @@ -75,6 +75,7 @@ public void run() { while (true) { cleanupLogging(); + ConsoleProxy.cleanupExpiredReconnectGrants(); bReportLoad = false; if (logger.isDebugEnabled()) { diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java index b844ab1aaa02..22cd546a78a9 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java @@ -177,6 +177,7 @@ public void run() { } } logger.info("Connection with client [{}] [IP: {}] is dead.", clientId, clientSourceIp); + ConsoleProxy.grantReconnectWindow(sessionUuid, clientSourceIp); } catch (IOException e) { logger.error("Error on VNC client", e); } diff --git a/systemvm/agent/conf/consoleproxy.properties b/systemvm/agent/conf/consoleproxy.properties index 361b0a33a054..6255a6906524 100644 --- a/systemvm/agent/conf/consoleproxy.properties +++ b/systemvm/agent/conf/consoleproxy.properties @@ -22,3 +22,4 @@ consoleproxy.jarDir=./applet/ consoleproxy.viewerLinger=180 consoleproxy.reconnectMaxRetry=5 consoleproxy.defaultBufferSize=65536 +consoleproxy.sessionReconnectGraceSeconds=1 From bfd5d0a8b2d816741c9a70b60e0a199492df1710 Mon Sep 17 00:00:00 2001 From: nvazquez Date: Tue, 28 Jul 2026 12:15:03 -0300 Subject: [PATCH 4/4] Introduce zone setting to control the reconnection window for console sessions --- .../consoleproxy/ConsoleProxyManager.java | 3 ++ .../consoleproxy/ConsoleProxyManagerImpl.java | 6 ++- .../com/cloud/consoleproxy/ConsoleProxy.java | 42 ++++++++++++------- .../consoleproxy/ConsoleProxyNoVncClient.java | 2 +- systemvm/agent/conf/consoleproxy.properties | 1 - 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java index 47d1a306e4d9..4e71d78fcbbd 100644 --- a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java +++ b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java @@ -84,6 +84,9 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService { ConfigKey ConsoleProxyDisableRpFilter = new ConfigKey<>(Boolean.class, "consoleproxy.disable.rpfilter", "Console Proxy", "true", "disable rp_filter on console proxy VM public interface", true, ConfigKey.Scope.Zone, null); + ConfigKey ConsoleProxySessionReconnectionWindow = new ConfigKey<>(Long.class, "consoleproxy.session.reconnection.window", "Console Proxy", "0", + "Reconnection window (in milliseconds) for client IPs to the same session on console proxy VM", true, ConfigKey.Scope.Zone, null); + ConfigKey ConsoleProxyLaunchMax = new ConfigKey<>(Integer.class, "consoleproxy.launch.max", "Console Proxy", "10", "maximum number of console proxy instances per zone can be launched", false, ConfigKey.Scope.Zone, null); diff --git a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 192c14b7f0bf..796fa7b48a1a 100644 --- a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -1210,6 +1210,10 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl if (Boolean.TRUE.equals(disableRpFilter)) { buf.append(" disable_rp_filter=true"); } + Long sessionReconnectionWindow = ConsoleProxySessionReconnectionWindow.valueIn(datacenterId); + if (sessionReconnectionWindow != null && sessionReconnectionWindow > 0) { + buf.append(" session_reconnection_window=").append(sessionReconnectionWindow); + } String msPublicKey = configurationDao.getValue("ssh.publickey"); buf.append(" authorized_key=").append(VirtualMachineGuru.getEncodedMsPublicKey(msPublicKey)); @@ -1588,7 +1592,7 @@ public ConfigKey[] getConfigKeys() { return new ConfigKey[] {ConsoleProxySslEnabled, NoVncConsoleDefault, NoVncConsoleSourceIpCheckEnabled, ConsoleProxyServiceOffering, ConsoleProxyCapacityStandby, ConsoleProxyCapacityScanInterval, ConsoleProxyRestart, ConsoleProxyUrlDomain, ConsoleProxySessionMax, ConsoleProxySessionTimeout, ConsoleProxyDisableRpFilter, ConsoleProxyLaunchMax, ConsoleProxyManagementLastState, ConsoleProxyServiceManagementState, NoVncConsoleShowDot, - ConsoleProxyVmUserData}; + ConsoleProxyVmUserData, ConsoleProxySessionReconnectionWindow}; } protected ConsoleProxyStatus parseJsonToConsoleProxyStatus(String json) throws JsonParseException { diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java index daf1122656fe..0cb1c4805dac 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java @@ -86,7 +86,7 @@ public class ConsoleProxy { private static final Object allowedSessionsLock = new Object(); private static final Map sessionReconnectGrants = new ConcurrentHashMap<>(); - static int sessionReconnectGraceSeconds = 1; + private static long sessionReconnectionWindowMs = 0L; // Invoked through reflection public static void addAllowedSession(String sessionUuid) { @@ -94,23 +94,34 @@ public static void addAllowedSession(String sessionUuid) { } /** - * Grant a short, single-use window to reconnect with the same session UUID in case of a disconnection. + * Grant the client IP a reconnection window of #{@link #sessionReconnectionWindowMs} ms to the same session UUID in case of a disconnection. * The grant is bound to the client IP that was using the session so it cannot be redeemed by another client. * @param sessionUuid session UUID to grant a reconnect window for * @param clientIp source IP of the client the session was granted to */ - public static void grantReconnectWindow(String sessionUuid, String clientIp) { - sessionReconnectGrants.put(sessionUuid, new ReconnectGrant(System.currentTimeMillis() + sessionReconnectGraceSeconds * 1000L, clientIp)); + public static void grantReconnectWindowForSessionAndClientIp(String sessionUuid, String clientIp) { + if (sessionReconnectionWindowMs > 0) { + ReconnectGrant grant = new ReconnectGrant(System.currentTimeMillis() + sessionReconnectionWindowMs, clientIp); + sessionReconnectGrants.put(sessionUuid, grant); + } } - private static boolean consumeReconnectGrant(String sessionUuid, String clientIp) { + /** + * True if the session UUID has been granted reconnection, within the reconnection window #{@link #sessionReconnectionWindowMs}. + */ + private static boolean isSessionReconnectionGrantedForClientIp(String sessionUuid, String clientIp) { ReconnectGrant grant = sessionReconnectGrants.remove(sessionUuid); - if (grant == null || grant.isExpired(System.currentTimeMillis())) { + if (grant == null) { + return false; + } + if (grant.isExpired(System.currentTimeMillis())) { + LOGGER.warn("Rejecting reconnection for session {} as the reconnect window: {}ms is already expired", + sessionUuid, sessionReconnectionWindowMs); return false; } if (grant.clientIp != null && !grant.clientIp.equals(clientIp)) { - LOGGER.warn("Rejecting reconnect for session " + sessionUuid + " as it was requested from IP " + - clientIp + " but the reconnect window was granted to IP " + grant.clientIp); + LOGGER.warn("Rejecting reconnection for session {} as it was requested from IP {} " + + "but the session was granted to IP {}", sessionUuid, clientIp, grant.clientIp); return false; } return true; @@ -216,10 +227,10 @@ private static void configProxy(Properties conf) { LOGGER.info("Setting defaultBufferSize=" + defaultBufferSize); } - s = conf.getProperty("consoleproxy.sessionReconnectGraceSeconds"); + s = conf.getProperty("session_reconnection_window"); if (s != null) { - sessionReconnectGraceSeconds = Integer.parseInt(s); - LOGGER.info("Setting sessionReconnectGraceSeconds=" + sessionReconnectGraceSeconds); + sessionReconnectionWindowMs = Long.parseLong(s); + LOGGER.info("Setting sessionReconnectionWindowMs=" + sessionReconnectionWindowMs); } } @@ -266,11 +277,12 @@ public static ConsoleProxyAuthenticationResult authenticateConsoleAccess(Console String sessionUuid = param.getSessionUuid(); synchronized (allowedSessionsLock) { if (allowedSessions.remove(sessionUuid)) { - LOGGER.debug("Acquiring the session " + sessionUuid + " for use"); - } else if (consumeReconnectGrant(sessionUuid, param.getClientIp())) { - LOGGER.info("Reconnecting the session " + sessionUuid + " after a dropped connection"); + LOGGER.debug("Acquiring the session {} from client IP {}", sessionUuid, param.getClientIp()); + } else if (isSessionReconnectionGrantedForClientIp(sessionUuid, param.getClientIp())) { + LOGGER.info("Reconnecting the session {} after a dropped connection", sessionUuid); + return authResult; } else { - LOGGER.info("Session " + sessionUuid + " has already been used, cannot connect"); + LOGGER.info("Invalid or already used session {}, cannot connect", sessionUuid); authResult.setSuccess(false); return authResult; } diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java index 22cd546a78a9..2ac85e5c5d33 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java +++ b/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java @@ -177,7 +177,7 @@ public void run() { } } logger.info("Connection with client [{}] [IP: {}] is dead.", clientId, clientSourceIp); - ConsoleProxy.grantReconnectWindow(sessionUuid, clientSourceIp); + ConsoleProxy.grantReconnectWindowForSessionAndClientIp(sessionUuid, clientSourceIp); } catch (IOException e) { logger.error("Error on VNC client", e); } diff --git a/systemvm/agent/conf/consoleproxy.properties b/systemvm/agent/conf/consoleproxy.properties index 6255a6906524..361b0a33a054 100644 --- a/systemvm/agent/conf/consoleproxy.properties +++ b/systemvm/agent/conf/consoleproxy.properties @@ -22,4 +22,3 @@ consoleproxy.jarDir=./applet/ consoleproxy.viewerLinger=180 consoleproxy.reconnectMaxRetry=5 consoleproxy.defaultBufferSize=65536 -consoleproxy.sessionReconnectGraceSeconds=1