Skip to content

Bound every plx_plex test server's accept, and give its deadlines room - #1229

Merged
GLinnik21 merged 1 commit into
mainfrom
fix/plx-plex-test-accept-hang
Nov 4, 2026
Merged

GLinnik21 merged 1 commit into
mainfrom
fix/plx-plex-test-accept-hang

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

What hung

make check's cargo stage hung for about an hour, twice. A sample of the stuck plx_plex test binary showed:

  • the test thread of plx_plex::http::tests::a_completed_500_cannot_become_a_deadline_after_the_caller_crosses_the_boundary (http.rs) blocked in JoinHandle::join (server.join());
  • its fixture's server thread blocked for ever in TcpListener::accept().

Root cause

The test gives request_until_outcome a 250 ms caller deadline. request_with checks the clock before it opens a socket and returns Deadline without dialing once the deadline has passed. On a loaded host (the python half of make check runs beside the cargo half) the client can reach 250 ms before its first connect. Nobody connects, the server thread's blocking accept() never returns, and join() never returns. A run that should have failed, or should never have depended on the clock, hung the whole suite instead. The sibling tests share the shape (a_transport_reset_..., only_the_timer_... with an 80 ms deadline, and client.rs's malformed_2xx_... with an inlined copy of cross).

Fix

  1. One bounded accept, in the shared fixture layer. plx_base::testnet is already the repo's single fixture accept and plx_plex already used it, so it gains the bounded forms instead of a helper private to http.rs (five files needed it):
    • accept_within(listener, wait): polls a nonblocking listener, returns a TimedOut error naming the listener if nobody connects, and still hands back a blocking socket (the Darwin fix testnet::accept exists for).
    • serve_once(listener, wait, serve): spawns the server thread; if no client arrives it panics with "its client never arrived", so the test's join() fails after CLIENT_WAIT (10 s) instead of blocking.
    • Every hand-written blocking accept() test server in plx_plex goes through them: http.rs, plex/notify.rs, plex/client.rs, plex/collections.rs, plex/transcoder.rs. The last three plus client.rs are devtriggers tests that make test-crate does not enable. The two pin tests' stop-flag pollers in http.rs get a CLIENT_WAIT bound (an assertion failing before stop was set left their thread scope joining them for ever). The "must not dial" asserts were never servers and are unchanged.
  2. The deadline tests stop racing the scheduler. The 250 ms and 80 ms deadlines become testnet::LOOPBACK_DEADLINE (2 s). It is far above any scheduling delay on a millisecond loopback exchange, and below plx_net's 15 s media_stall_budget(): past that, request_until_outcome reads an expiry as the transport's liveness (Transport(None)), not the caller's Deadline, so the silent-peer test would fail outright. Each test keeps its intent: the completed 500 and the reset are decided before the boundary and read after it; the silent peer is still stopped by the caller's timer. Cost: testnet::cross (now shared with client.rs, replacing its inline copy) sleeps out the 2 s, so the 500 and reset tests (and malformed_2xx_...) take about 2 s each, and the silent-peer test 2 s. They run in parallel, so suite wall time moves by about 2 s.

Regression tests: testnet's own four (no client gives an error or a failed join within the wait, not a hang; the accepted socket blocks; cross), and an_expired_caller_deadline_is_a_deadline_without_dialing_and_a_bounded_accept_says_so in http.rs, which pins the precheck behind the hang.

Proof

Reproduction (before): the 500 test with an already-expired deadline (let deadline = Instant::now();, scratch edit, not committed) under make test-crate C=plx_plex T=a_completed_500_cannot. It never finished: libtest printed "has been running for over 60 seconds" and I killed it at 131 s. sample showed the test thread in std::thread::JoinHandle::join (http.rs:1260) and the server thread at http.rs:1247 (accept).

Reproduction (after): the same scratch edit on the fixed code fails after 10.00 s with:

thread 'loopback server' panicked at base/src/testnet.rs:90:37:
loopback server: its client never arrived: no client reached 127.0.0.1:53251 within 10s
...
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 767 filtered out; finished in 10.00s

Tests:

  • make test-crate C=plx_base T=testnet: test result: ok. 4 passed; 0 failed
  • make test-crate C=plx_plex: test result: ok. 768 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 9.91s
  • cargo test --lib -p plx_plex --features devtriggers (compiles and runs the gated client.rs, collections.rs, transcoder.rs tests): test result: ok. 768 passed; 0 failed

Under load: the affected tests run 30 times each with 20 yes CPU hogs on 10 cores (killed by a trap). Default features, filters http::tests plex::notify: 30/30 iterations ok. 53 passed; 0 failed. With --features devtriggers adding malformed_2xx transcode_ resource_close mde_never authorization_and_absence: 30/30 iterations ok. 65 passed; 0 failed. Every iteration reported N > 0 passed. One caveat: I could not trigger the natural race on the old code with CPU load alone (the old binary under 60 hogs passed 30/30), so the deterministic expired-deadline reproduction above is the evidence for the hang mechanism; the loop shows the fixed tests are stable under load.

make check on the committed tree (clean git status --short before and after), exit 0:

test result: ok. 768 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 16.21s   (plx_plex)
test result: ok. 768 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 21.77s   (plx_plex, second cargo pass)
==== check: python — ok (1649s) ====
==== check: rest — ok (1066s) ====
==== check: 125 steps — all ok (1065s wall, 382s cpu, 4 at once; slowest: test_pr_land.py 406s, test_ci_workflows.py 253s, test_build_gc.py 207s) ====
==== check: harness — ok (1648s) ====

Not in this PR

The same blocking-accept() shape exists in plx_net's test fixtures (stream_deadline_connect_tests.rs:47 with an 80 ms deadline, stream_test_support.rs::one_shot_server used by stream_header_body_tests.rs:310 with 250 ms, and others). http_open_with_timeouts also returns Deadline before dialing, so they can hang the same way. They are the same migration onto testnet::serve_once; left for a follow-up to keep this PR to plx_plex.

🤖 Generated with Claude Code

`make check` hung for about an hour, twice. A `sample` of the stuck plx_plex test binary showed
`http::tests::a_completed_500_cannot_become_a_deadline_after_the_caller_crosses_the_boundary`
blocked in `server.join()`, and its server thread blocked for ever in `TcpListener::accept()`.

The test gives `request_until_outcome` a 250 ms caller deadline. When the host is loaded (the
python half of `make check` runs beside the cargo half) the client can reach that deadline before
it ever connects, and `request_with` returns `Deadline` WITHOUT dialing once the clock has passed.
Nobody connects, so the fixture's blocking `accept()` never returns and the joiner never
returns. A run that should have failed, or never have depended on the clock at all, hung the
whole suite instead. Reproduced by giving that test an already-expired deadline: it ran 130 s
until killed, with `join` in the test thread and `accept` in the server thread.

Two fixes, both systematic:

* `plx_base::testnet` (the repo's one fixture accept, which `plx_plex` already used) gains the
  bounded forms: `accept_within(listener, wait)` returns a TimedOut error naming the listener, and
  `serve_once(listener, wait, serve)` spawns the server thread and panics with "its client never
  arrived" when nobody connects, so the test's `join()` fails after `CLIENT_WAIT` (10 s) instead
  of blocking. Every hand-written blocking `accept()` test server in plx_plex (http.rs,
  plex/notify.rs, plex/client.rs, plex/collections.rs, plex/transcoder.rs; the last four are
  `devtriggers` tests, which `make test-crate` does not enable) now goes through them, and keeps
  the Darwin blocking-socket fix `testnet::accept` exists for. The two stop-flag pollers
  in the pin tests get a `CLIENT_WAIT` bound too (an assertion failing before `stop` was set left
  their thread scope joining them for ever); the "must not dial" asserts were never servers and
  are unchanged.
* The deadline tests no longer race the scheduler. The 250 ms and 80 ms deadlines become
  `testnet::LOOPBACK_DEADLINE` (2 s): far above any delay a loaded host adds to a millisecond
  exchange, and under plx_net's 15 s inactivity budget, past which `request_until_outcome` would
  read the expiry as the transport's liveness rather than the caller's deadline. Each test keeps
  its intent: the completed 500 and the reset are decided before the boundary and read after it
  (`testnet::cross`, now shared with client.rs's copy, sleeps out the 2 s), and the silent peer is
  still stopped by the caller's timer.

Regression tests: `testnet`'s own (no client gives an error / a failed join within the wait, the
accepted socket blocks, `cross`), and `an_expired_caller_deadline_is_a_deadline_without_dialing_
and_a_bounded_accept_says_so` in http.rs, which pins the precheck behind the hang.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit b20a710 into main Nov 4, 2026
20 checks passed
@GLinnik21
GLinnik21 deleted the fix/plx-plex-test-accept-hang branch November 4, 2026 13:02
GLinnik21 added a commit that referenced this pull request Nov 4, 2026
…#1232)

plx_net's test servers blocked in TcpListener::accept() for a client the
test under them might never send. A loaded host that carried a short caller
deadline past before the opener's first connect left the accept with no
client, and the join that waited on it hung `make check` instead of failing
it, as plx_plex's did before #1229.

- plx_base::testnet::accept_client(listener, wait) is a bounded accept that
  panics "its client never arrived"; serve_once accepts through it.
- Every spawned or scoped blocking-accept server in plx_net goes through
  testnet, and the request reads in the scope servers and one-shot fixtures
  are bounded too, so a panicking client cannot park its server in read.
- The two deadlines that raced the first dial (80 ms and 300 ms) use
  LOOPBACK_DEADLINE; the slice-count bound is rescaled to the span waited.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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