Skip to content

Make the stalled-browser relay test reach a stalled send - #45

Merged
rogers-andrew merged 1 commit into
cppalliance:masterfrom
rogers-andrew:fix-stalled-browser-relay-test
Dec 3, 2026
Merged

rogers-andrew merged 1 commit into
cppalliance:masterfrom
rogers-andrew:fix-stalled-browser-relay-test

Conversation

@rogers-andrew

Copy link
Copy Markdown
Contributor

This pull request fixes stalled_browser_cleanup_is_bounded_after_gateway_disconnect, a test of workshop-server that fails on Linux on every run, on unchanged code (#32 noted the failure). CI runs the tests of the Workshop crates only in its Windows job, so CI has not shown it. The change touches two test files and no product code.

The test never reached a stalled send

The test's stand-in Gateway sent one 32 MiB binary frame. The relay connects to the Gateway with connect_async, so it reads the Gateway under tungstenite's default WebSocketConfig, whose max_frame_size is 16 MiB. The relay refuses the frame as soon as its header arrives, closes the browser, and returns, which drops both sockets. It never starts a browser send, so nothing stalls.

  • On Linux, the stand-in's send fails when the relay drops the socket, so the probe never fires, and the test fails after RECV_TIMEOUT at "the Gateway fills the relay's browser send".
  • Where the stand-in's send completes anyway, the browser then receives the relay's Close, and the test passes without a stalled send. I could not run Windows here, but the Windows job passing is consistent with this path.

A second problem sat behind the first. The test first waited 750 ms, longer than RELAY_IO_DEADLINE, before the browser's first read. c2e70f6e removed that wait as redundant, but the read is what lets a stalled send finish. With the frame made 15 MiB, under the cap, the browser received the whole frame within 69 ms and the last assertion failed.

Why the test is wrong and the relay is right

  • The relay already does what the test describes. Each relay socket operation runs under bounded, which gives up after RELAY_IO_DEADLINE, and the relay then returns and drops both sockets.
  • The 16 MiB cap is tungstenite's default. The relay carries Realtime transcription events, which are far smaller, and refusing a larger frame by closing the browser is sound for a relay. Raising the cap would be a product decision, and a test should not force it.
  • A version of the test that really does stall a send passes against the relay unchanged, and fails when the deadline is raised past the test's wait (below).

What the test does now

  • The stand-in Gateway sends up to STALL_FRAMES (16) frames of STALL_FRAME_BYTES (8 MiB). Each frame is under the cap, and together they are more than the sockets between the relay and the browser can buffer. It then reports when the relay drops the Gateway socket, which the relay does only once it has given up on the browser.
  • The browser reads nothing until that report, so no read can make room for the stalled send. This is the event-driven wait that c2e70f6e intended, in place of the 750 ms sleep.
  • Frames that the sockets took before the stall can arrive whole, so the test asserts that fewer than all 16 reach the browser, instead of checking the first message.
  • The test is renamed a_stalled_browser_send_is_canceled_within_the_relay_deadline, because the relay now gives up while the Gateway is still connected, not after it disconnects.

How it was checked, on Linux

  • The new test passed 20 runs out of 20, each in about 0.55 s: the relay's 500 ms deadline plus cleanup.
  • With RELAY_IO_DEADLINE raised to 60 s, it fails after 10 s at "the relay gives up on a browser that never reads".
  • cargo nextest run --locked -p workshop -p workshop-server -p workshop-server-api (with a stub Gateway sidecar staged, as CI does), cargo clippy --locked -p workshop -p workshop-server -p workshop-server-api --all-targets with CARGO_BUILD_WARNINGS=deny, cargo fmt --all --check, and cargo test --locked -p build-xtask pass, apart from one unrelated test noted below.
  • In one of two full runs, gateway::tests::identity::server_publication_replaces_a_mismatched_candidate_and_cleans_it_up, in the workshop desktop crate, failed after 81 s with HealthFailed. That was under load, beside the Gateway-spawning tests. Run alone it passed three times out of three, in about 0.35 s. This change does not touch it.
  • Not run here: the Windows job, and dylint, which is not installed on this machine. CI runs both.

🤖 Generated with Claude Code

@rogers-andrew rogers-andrew self-assigned this Dec 2, 2026

@awheeler294 awheeler294 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks fine to me

The test sent one 32 MiB frame, but the relay reads the Gateway under
tungstenite's default 16 MiB `max_frame_size`, so it refused the frame
before forwarding it and no browser send ever stalled. On Linux the
Gateway double's send then failed when the relay dropped the socket, the
probe never fired, and the test failed after `RECV_TIMEOUT` at its first
wait. Behind that, the browser read as soon as the probe fired, and a read
makes room for a stalled send to finish inside `RELAY_IO_DEADLINE`; the
750 ms wait that c2e70f6 removed had been holding that read back.

- `send_frames_until_the_relay_lets_go` sends up to `STALL_FRAMES` frames
  of `STALL_FRAME_BYTES`, each under the frame cap and together more than
  the sockets between the relay and the browser hold, then reports when
  the relay drops the Gateway socket, which it does only once it has given
  up on the browser.
- The browser reads nothing until that report, and the test asserts that
  fewer than all the frames reach it, since frames the sockets took before
  the stall can arrive whole.
- The test is now `a_stalled_browser_send_is_canceled_within_the_relay_deadline`:
  the relay gives up while the Gateway is still connected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rogers-andrew
rogers-andrew marked this pull request as ready for review December 3, 2026 04:45
@rogers-andrew
rogers-andrew force-pushed the fix-stalled-browser-relay-test branch from 0c0248c to 6946d46 Compare December 3, 2026 04:45
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fb5f264b-191b-4bdb-8b01-067a16e320f9
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@rogers-andrew
rogers-andrew merged commit 6946d46 into cppalliance:master Dec 3, 2026
12 checks passed
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.

2 participants