Skip to content

Fix flaky remote-desktop socket tests (handshake timeout deadlock)#213

Merged
JE-Chen merged 1 commit into
devfrom
fix/flaky-remote-desktop-socket-tests
Jun 18, 2026
Merged

Fix flaky remote-desktop socket tests (handshake timeout deadlock)#213
JE-Chen merged 1 commit into
devfrom
fix/flaky-remote-desktop-socket-tests

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 18, 2026

Copy link
Copy Markdown
Member

Problem

Two tests intermittently hung the whole headless suite (pytest-timeout
hard-kills the process, so a single hang fails the run):

  • test_remote_desktop_tls.py::test_plain_viewer_against_tls_host_fails
  • test_remote_desktop_websocket.py::test_plain_tcp_viewer_against_ws_host_is_rejected

Root cause

RemoteDesktopViewer.connect(timeout=...) set the auth-handshake socket
timeout to max(_DEFAULT_AUTH_TIMEOUT_S=60, timeout), so an explicit
short timeout (the tests pass 2s / 30s to detect a protocol mismatch) was
floored to 60s. A plain viewer connecting to a TLS/WS host then blocked
~60s on a handshake that never completes — the same 60s as the test
timeout, so it raced and intermittently hung.

Fix

  • Bound the handshake by the caller's timeout (the handshake is a tiny
    HMAC exchange; the connect budget is ample, and callers needing more
    pass a larger timeout). Removes the unused auth-timeout constant.
  • Tighten the WebSocket rejection test to a 2s budget.

Both mismatch tests now fail fast and deterministically (~2s each, was a
60s race). Full test_remote_desktop_tls.py + test_remote_desktop_websocket.py
pass in ~6s.

RemoteDesktopViewer.connect floored the auth-handshake socket timeout at
max(60s, timeout), so an explicit short timeout (e.g. 2s) was ignored.
When a plain viewer hit a TLS host (or a plain viewer hit a WS host) the
two sides each blocked for 60s on a handshake that never completed —
racing the 60s test timeout and intermittently hanging the suite.

Bound the handshake by the caller's timeout instead (the handshake is a
tiny HMAC exchange, so the connect budget is ample; callers needing
longer pass a larger timeout). Drop the now-unused auth-timeout constant
and tighten the WebSocket rejection test to a 2s budget so both
mismatch tests fail fast and deterministically.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 1 duplication

Metric Results
Complexity 0
Duplication 1

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@JE-Chen JE-Chen merged commit 1a3f045 into dev Jun 18, 2026
16 checks passed
@JE-Chen JE-Chen deleted the fix/flaky-remote-desktop-socket-tests branch June 18, 2026 18:00
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant