Skip to content

[ConsoleProxy] Performance fixes on concurrency and closing console sessions sockets and introduce reconnection window for console sessions - #13683

Draft
nvazquez wants to merge 4 commits into
apache:4.22from
shapeblue:422-console-intermittent-issue
Draft

[ConsoleProxy] Performance fixes on concurrency and closing console sessions sockets and introduce reconnection window for console sessions#13683
nvazquez wants to merge 4 commits into
apache:4.22from
shapeblue:422-console-intermittent-issue

Conversation

@nvazquez

@nvazqueznvazquez commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

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.

    • To fix this, a new zone setting is added consoleproxy.session.reconnection.window with 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.

    • Before the fix: After opening multiple sessions for the same VM, each new session opens a new socket connection on the KVM host on the VNC port but was not closed after closing the console browser tab.
[root@ref-trl-12127-k-Mol9-nicolas-vazquez-kvm2 ~]# ss -tnp | grep 5901
ESTAB 0 55 10.0.33.112:5901 10.0.39.91:43024 users:(("qemu-kvm",pid=77212,fd=38)) ESTAB 0 55 10.0.33.112:5901 10.0.39.91:51796 users:(("qemu-kvm",pid=77212,fd=36)) ESTAB 0 0 10.0.33.112:5901 10.0.39.91:43008 users:(("qemu-kvm",pid=77212,fd=37)) ESTAB 0 0 10.0.33.112:5901 10.0.39.91:60794 users:(("qemu-kvm",pid=77212,fd=35)) 
  • After the fix: Each time a console session is acquired, then only one socket connection remains open per VM, and when it is closed then no connections remain open:
[root@ref-trl-12127-k-Mol9-nicolas-vazquez-kvm2 ~]# ss -tnp | grep 5901
[root@ref-trl-12127-k-Mol9-nicolas-vazquez-kvm2 ~]# ss -tnp | grep 5901
ESTAB 0 0 10.0.33.112:5901 10.0.39.99:41826 users:(("qemu-kvm",pid=77212,fd=35)) [root@ref-trl-12127-k-Mol9-nicolas-vazquez-kvm2 ~]# ss -tnp | grep 5901
[root@ref-trl-12127-k-Mol9-nicolas-vazquez-kvm2 ~]# ss -tnp | grep 5901
ESTAB 0 0 10.0.33.112:5901 10.0.39.99:36836 users:(("qemu-kvm",pid=77212,fd=35)) 

Fixes: #13422

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

  • Replaced the agent.zip file on /usr/share/cloudstack-common/vms/ for each KVM host and recreated the CPVM
  • Acquired multiple console sessions and verified the the established using the ss -tnp command for VM's VNC ports
  • Using the default value consoleproxy.session.reconnection.window = 0, observe no changes on console sessions reconnection
  • Set consoleproxy.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 timeframe

How did you try to break this feature and the system with this change?

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.allowedSessions concurrency-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
FileDescription
services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/NoVncClient.javaAdds 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.javaStores the underlying NioSocket and exposes close() to release it.
services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketHandler.javaAdds a close() contract to the handler interface.
services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocket.javaAdds a close() method to release the socket channel and selectors.
services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVNCHandler.javaEnsures viewer teardown is triggered on WebSocket close and hardens remote-address logging.
services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyNoVncClient.javaEnsures closeClient() closes the underlying NoVncClient before removing the viewer.
services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.javaSwitches 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

codecovBot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 4.80769% with 99 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.69%. Comparing base (0339f31) to head (bfd5d0a).
⚠️ Report is 1 commits behind head on 4.22.

Files with missing linesPatch %Lines
...main/java/com/cloud/consoleproxy/ConsoleProxy.java8.69%42 Missing ⚠️
.../com/cloud/consoleproxy/vnc/network/NioSocket.java0.00%20 Missing ⚠️
...n/java/com/cloud/consoleproxy/vnc/NoVncClient.java0.00%16 Missing ⚠️
...m/cloud/consoleproxy/ConsoleProxyNoVNCHandler.java0.00%10 Missing ⚠️
...consoleproxy/vnc/network/NioSocketHandlerImpl.java0.00%4 Missing ⚠️
...om/cloud/consoleproxy/ConsoleProxyManagerImpl.java0.00%3 Missing ⚠️
...om/cloud/consoleproxy/ConsoleProxyNoVncClient.java0.00%3 Missing ⚠️
...a/com/cloud/consoleproxy/ConsoleProxyGCThread.java0.00%1 Missing ⚠️
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 
FlagCoverage Δ
uitests3.69% <ø> (ø)
unittests18.77% <4.80%> (-0.01%)⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nvazquez

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@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.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18654

@DaanHooglandDaanHoogland linked an issue Jul 24, 2026 that may be closed by this pull request

@DaanHooglandDaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

@Pearl1594Pearl1594 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

@nvazquez
nvazquez marked this pull request as draft July 27, 2026 01:16
@nvazquez

Copy link
Copy Markdown
ContributorAuthor

Marked on draft as still working on fixing the issues reported on: #13422

@nvazquez
nvazquez marked this pull request as ready for review July 27, 2026 15:01
@nvazquez
nvazquez requested a review from CopilotJuly 27, 2026 15:11

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment threadsystemvm/agent/conf/consoleproxy.properties Outdated
@nvazquez
nvazquez marked this pull request as draft July 28, 2026 03:19
@nvazquez
nvazquez marked this pull request as ready for review July 28, 2026 15:18
@nvazquez

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@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.

@nvazqueznvazquez changed the title [ConsoleProxy] Performance fixes on concurrency and closing console sessions sockets[ConsoleProxy] Performance fixes on concurrency and closing console sessions sockets and introduce reconnection window for console sessionsJul 28, 2026
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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should "return true" only if client IPs match, and "return false" by default ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @weizhouapache not only client IPs match but also the reconnection attempt is within the reconnection window/timeframe

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18698

@nvazquez

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@nvazquez a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@weizhouapacheweizhouapache left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-16643)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 54818 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr13683-t16643-kvm-ol8.zip
Smoke tests completed. 148 look OK, 1 have errors, 0 did not run
Only failed and skipped tests results shown below:

TestResultTime (s)Test File
test_01_ssl_offloading_isolated_networkFailure704.80test_ssl_offloading.py
test_02_ssl_offloading_project_vpcFailure712.14test_ssl_offloading.py

@nvazquez
nvazquez marked this pull request as draft August 6, 2026 16:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intermittent Console Proxy Failure in 4.22.1.0

7 participants

@nvazquez@blueorangutan@DaanHoogland@Pearl1594@weizhouapache@vladimirpetrov