Skip to content

console-proxy: stop busy-spinning in NoVncClient.waitForNoVNCReply - #14542

Open
Daniel-Pereira-Linux wants to merge 1 commit into
apache:4.22from
Daniel-Pereira-Linux:fix/novnc-wait-busy-spin
Open

Daniel-Pereira-Linux wants to merge 1 commit into
apache:4.22from
Daniel-Pereira-Linux:fix/novnc-wait-busy-spin

Conversation

@Daniel-Pereira-Linux

Copy link
Copy Markdown

Description

This PR fixes console proxy threads spinning at 100% CPU in NoVncClient.waitForNoVNCReply() when noVNC never replies.

waitForNoVNCReply() looped on isWaitForNoVnc() with no sleep, no timeout and no check that the connection was still alive. If the VNC socket or the websocket was closed before noVNC replied (for example, the VM is stopped or rebooted while the console is connecting), nothing ever cleared the flag and the thread spun forever, until the cloud service in the CPVM was restarted.

Changes:

  • waitForNoVNCReply() now waits on the existing lock instead of spinning. setWaitForNoVnc() and close() wake it up. It gives up with a CloudRuntimeException when the client is closed, the thread is interrupted, or no reply arrives within 30 seconds.
  • Since the wait can now fail, the viewer thread in ConsoleProxyNoVncClient catches RuntimeException as well as IOException, and closes the client and the session, so the VNC socket and the websocket are not left open.
  • The wait flag is now set before sending the message that noVNC replies to (security result and server init). Otherwise a fast reply could be missed and, with the new timeout, a healthy session would be dropped after 30 seconds.

Fixes: #14538

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

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

How Has This Been Tested?

Unit tests only. I have not tested this on a real CPVM with a KVM VM being restarted during the console connection.

  • Added NoVncClientTest and extended ConsoleProxyNoVncClientTest: reply arrives, no wait pending, timeout, client closed, thread interrupted, handshake failure closes the session, and closing the viewer while waiting stops the worker.
  • Ran the unit tests of services/console-proxy/server (with checkstyle) on JDK 21: all pass.
  • With the previous NoVncClient, the new tests fail (including the worker that never stops after closeClient()), which reproduces the issue at unit test level.

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

  • Closing the client while another thread is waiting, and interrupting the waiting thread.
  • A noVNC reply that arrives before the message is fully sent (ordering of the wait flag).
  • A handshake failure in the viewer thread, to check the VNC socket and the websocket are released.

Not covered: TLS/VeNCrypt backends, the tunnel and websocket-proxy paths.

waitForNoVNCReply() looped on isWaitForNoVnc() with no sleep, timeout or
check that the connection was still alive. If the VNC socket or the
websocket was closed before noVNC replied (e.g. VM restarted while the
console was connecting), the thread spun at 100% CPU forever.

Wait on the existing lock instead, woken by setWaitForNoVnc() and
close(), and fail with a CloudRuntimeException when the client is closed,
the thread is interrupted, or no reply arrives within 30 seconds.

Since the wait can now fail, the viewer thread closes the client and the
session on any RuntimeException, and the wait flag is set before sending
the message that noVNC replies to, so a fast reply is not missed.

Fixes: apache#14538
@boring-cyborg

boring-cyborg Bot commented Oct 30, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

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

@DaanHoogland
DaanHoogland requested a review from nvazquez November 4, 2026 16:37
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.38%. Comparing base (56306ab) to head (40d527c).
⚠️ Report is 2 commits behind head on 4.22.

Files with missing lines Patch % Lines
...n/java/com/cloud/consoleproxy/vnc/NoVncClient.java 87.50% 0 Missing and 3 partials ⚠️
...om/cloud/consoleproxy/ConsoleProxyNoVncClient.java 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #14542      +/-   ##
============================================
+ Coverage     18.30%   18.38%   +0.07%     
- Complexity    16629    16715      +86     
============================================
  Files          5939     5939              
  Lines        537751   537775      +24     
  Branches      65924    65926       +2     
============================================
+ Hits          98460    98846     +386     
+ Misses       428085   427677     -408     
- Partials      11206    11252      +46     
Flag Coverage Δ
uitests 4.08% <ø> (ø)
unittests 19.47% <87.50%> (+0.07%) ⬆️

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.

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland 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 19921

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

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

This branch has not been deployed

No deployments
Sign up for free to 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.

Console proxy threads spin at 100% CPU in NoVncClient.waitForNoVNCReply() when noVNC never replies

3 participants