[ConsoleProxy] Performance fixes on concurrency and closing console sessions sockets and introduce reconnection window for console sessions - #13683
Conversation
There was a problem hiding this comment.
Pull request overview
This PR targets ConsoleProxy reliability and resource usage by (1) making the “allowed sessions” tracking safe under concurrent access, and (2) ensuring VNC-related connections are actively closed when a noVNC browser session ends, preventing lingering sockets on KVM hosts.
Changes:
- Introduces explicit close paths for NIO socket resources and noVNC client connections to avoid leaking VNC sockets.
- Makes
ConsoleProxy.allowedSessionsconcurrency-safe and guards one-time session consumption. - Ensances WebSocket close handling to trigger client teardown and make remote-address logging more robust.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/NoVncClient.java | Adds a close() method to shut down NIO, websocket, and tunnel socket resources. |
| services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketHandlerImpl.java | Stores the underlying NioSocket and exposes close() to release it. |
| services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketHandler.java | Adds a close() contract to the handler interface. |
| services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocket.java | Adds a close() method to release the socket channel and selectors. |
| services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVNCHandler.java | Ensures viewer teardown is triggered on WebSocket close and hardens remote-address logging. |
| services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.java | Ensures closeClient() closes the underlying NoVncClient before removing the viewer. |
| services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java | Switches allowedSessions to a concurrent set and synchronizes one-time session consumption; uses closeClient() when replacing viewers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 4.22 #13683 +/- ##
============================================
- Coverage 17.69% 17.69% -0.01%
Complexity 15833 15833
============================================
Files 5925 5925
Lines 533534 533627 +93
Branches 65273 65290 +17
============================================
- Hits 94421 94419 -2
- Misses 428434 428531 +97
+ Partials 10679 10677 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@blueorangutan package |
|
@nvazquez a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18654 |
|
Marked on draft as still working on fixing the issues reported on: #13422 |
…after acquiring a session
|
@blueorangutan package |
|
@nvazquez a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
| if (grant.clientIp != null && !grant.clientIp.equals(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; |
There was a problem hiding this comment.
should "return true" only if client IPs match, and "return false" by default ?
There was a problem hiding this comment.
Hi @weizhouapache not only client IPs match but also the reconnection attempt is within the reconnection window/timeframe
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18698 |
|
@blueorangutan test |
|
@nvazquez a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
Description
This PR addresses 3 issues:
In case of concurrent console proxy requests, 2 different threads could modify the allowedSessions set and cause problems accessing the console sessions\
Connection drop and reconnection failures (Intermittent Console Proxy Failure in 4.22.1.0 #13422): in cases in which a session has been properly acquired but after a few seconds declared as dead and then tried to reconnect, the CPVM prevented it as the session has already been acquired.
consoleproxy.session.reconnection.windowwith default value = 0, which sets a reconnection window for the same client IP once a connection is declared as dead.After closing the browser tab for a VM console session, it was observed that the connection remained open on the KVM host's VNC port.
Fixes: #13422
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
agent.zipfile on/usr/share/cloudstack-common/vms/for each KVM host and recreated the CPVMss -tnpcommand for VM's VNC portsconsoleproxy.session.reconnection.window= 0, observe no changes on console sessions reconnectionconsoleproxy.session.reconnection.window= 5000, recreate CPVM. Observe refreshing the browser tab allows the same client to reclaim back/reconnect to the same session. Also, if another session acquires the console session, the previous session could be reclaimed back within the reconnection window timeframeHow did you try to break this feature and the system with this change?