Skip to content

Bound every plx_net test server's accept, and give its deadlines room - #1232

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

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

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

What failed

plx_net's test servers can hang the suite the way plx_plex's did (#1229). A fixture thread blocks in TcpListener::accept() for a client the test under it may never send, and the test's join() (or a fixture's Drop) then waits for ever on a thread nobody will wake. http_open_until_result returns Deadline without dialing once its caller deadline has passed, so a loaded host that carries an 80 ms (or 300 ms) deadline past before the opener's first connect leaves the server's accept with no client. A run that should have failed hangs make check instead.

It happens on this Mac, without a scratch edit: the unmodified plx_net test binary, run under 30 yes CPU hogs on the two deadline tests, hung on the first of 100 runs (continue_slices_neither_end_an_open_early_nor_spin ... FAILED, then the process never exited: Scripted's Drop joined its accept).

Cause

Same as #1229: blocking accept() in a spawned or scoped test server + a short caller deadline that races the client's first dial. The review of #1229 named stream_deadline_connect_tests.rs:47 (80 ms) and stream_test_support.rs::one_shot_server; the triage below covers every accept() in rust-modules/net/src.

Fix

  • plx_base::testnet::accept_client(listener, wait) (new): accept_within for a server that cannot go on without its client; it panics ("its client never arrived", naming the listener) after wait, so the thread ends and whoever joins it fails. serve_once now accepts through it. Two new testnet tests pin it.
  • Every spawned/scoped blocking accept in plx_net goes through testnet: serve_once for one_shot_server, one_shot_echo, the redirect and User-Agent hop servers and the easy-path sent/served doubles (the first two also bound their request read); accept_client for the chunked-drain and keep-alive scope servers, Scripted and the interruptible-open peer. Those scope servers and the two one-shot fixtures also get a CLIENT_WAIT read timeout: HttpStream has no Drop, so a client that panics leaves its socket open and a server parked in read would hold the scope for ever (found in review). with_keepalive_listener's polling acceptor accepts through testnet::accept (Darwin accepted sockets become blocking, as on Linux).
  • The two deadlines that raced a dial take testnet::LOOPBACK_DEADLINE (2 s), above any delay a loaded host adds to a loopback connect and under plx_net's 15 s MEDIA_RECV_TIMEOUT_MS inactivity budget (past it the caller would not own the instant):
    • a_typed_open_reports_the_header_deadline_that_stopped_it (80 ms): still stopped by the caller's timer, graded LOOPBACK_DEADLINE / 2 ..< MEDIA_RECV_TIMEOUT_MS.
    • continue_slices_neither_end_an_open_early_nor_spin (300 ms): the slice count is graded against the span waited, 5 ..= 2 * deadline/slice, instead of 15 slices over 300 ms.

Triage of grep -rn 'accept()' rust-modules/net/src

Site Verdict
stream_test_support.rs one_shot_server, one_shot_echo spawned server: serve_once
stream_redirect.rs:579, stream_user_agent_tests.rs:53, net_wire_characterization_tests.rs:39 (sent), net_response_header_tests.rs:73 (served) spawned server, joined: serve_once
stream_chunked_drain_tests.rs x7, stream_keepalive_reuse_tests.rs x4 (first accept of each server) scoped server: accept_client
stream_checkpoint_tests.rs:45 (Scripted) spawned server joined by finish and Drop: accept_client
stream_deadline_connect_tests.rs:47 (typed open), :251 (interruptible open) serve_once / accept_client
stream_test_support.rs:241 (with_keepalive_listener) stop-flag poller, already bounded: now testnet::accept
stream_deadline_connect_tests.rs:202, stream_ipv6_resolution_tests.rs:282 same thread, after connect completed: cannot block, unchanged
stream_keepalive_reuse_tests.rs:304/363, stream_checkpoint_tests.rs:67, stream_ipv6_resolution_tests.rs:378/411, net_wire_characterization_tests.rs:131, net_response_header_tests.rs:148, stream_wire_characterization_tests.rs:131 nonblocking listener asked "did anybody dial?": unchanged
net.rs incoming() loops (1254, 1497, 1550, 1618) detached TLS doubles, no test joins them: unchanged
net.rs:4078, :4381 already testnet::accept with a stop flag/bound: unchanged
net/h2_reset_fixture.py:56 Python fixture, listener.settimeout(10): unchanged

Not changed, and still able to hold a failing run: the std::sync::Barrier waits in the chunked-drain tests (a server thread parks there if the test thread panics first) and their 200 ms elapsed-time asserts. Neither is an accept.

Proof

  1. Reproduction, before: scratch edit giving a_typed_open_reports_the_header_deadline_that_stopped_it an already-expired deadline (started + 80 ms -> started), make test-crate C=plx_net T=a_typed_open_reports_the_header_deadline_that_stopped_it: has been running for over 60 seconds, killed at 166 s. sample of the stuck binary: test thread in JoinHandle::join (stream_deadline_connect_tests.rs:68), server thread in TcpListener::accept (:47).
  2. Reproduction, after (same scratch edit on the fixed test, then reverted): FAILED ... finished in 10.00s, loopback server: its client never arrived: no client reached 127.0.0.1:<port> within 10s.
  3. make test-crate C=plx_net: test result: ok. 213 passed; 0 failed. make test-crate C=plx_base T=testnet: test result: ok. 6 passed; 0 failed.
  4. Loops under load (yes > /dev/null hogs from a script with an EXIT trap, checked afterwards: no yes survives; perl -e 'alarm shift; exec @ARGV' SECS per run):
    • the two deadline tests, 30 hogs, 100 runs: before 99 passed + 1 hung (the natural hang above), after 100 passed, 0 failed, 0 hung.
    • the whole plx_net test binary, 10 hogs, 30 runs: after 30 passed, 0 failed, 0 hung (the unmodified binary also passed 30 of 30 here; the narrow loop is the one that catches the race).
  5. make check (committed tree, clean git status), on this Mac:
    • the default-feature unit pass is green for every crate, including plx_net (test result: ok. 213 passed) and plx_base (test result: ok. 247 passed, with the two new testnet tests).
    • ==== check: cargo — FAILED, exit 2 (2970s) ==== / ==== check: python — stopped, a sibling branch failed (2974s) ====, from the second (devtriggers/hostsim) unit pass only, in crates this PR does not touch: plx_plex http::tests::a_completed_500_cannot_become_a_deadline_after_the_caller_crosses_the_boundary ("its client never arrived": the client did not dial within 10 s on a machine running six test binaries at once, which is testnet's bound doing its job on a stalled client) and plex::session::persistence::db8_policy_tests::arm_candidate_assembly_puts_the_canonical_wrapper_first; plx_media ff::hls_reserve_tests::a_pause_projection_spends_neither_reserve_nor_transport_liveness (a 50 ms watchdog; fails about 1 run in 20 on its own module, and in earlier make check runs of this tree) and ff::stall_guard_tests::a_hold_accepted_during_a_blocked_body_read_ends_that_read. This branch changes no file in plx_plex, plx_media or plx_session.

🤖 Generated with Claude Code

#1229 fixed the hang in plx_plex's test servers; its review found the same shape in plx_net. A
fixture thread blocks in `TcpListener::accept()` for a client the test under it may never send:
`http_open_until_result` (like `request_with`) returns `Deadline` WITHOUT dialing once its caller
deadline has passed, a loaded host can carry an 80 ms deadline past before the first `connect`, and
the test's `join()` then waits for ever on a thread nobody will ever wake. A run that should have
failed, or never depended on the clock, hung `make check` for an hour.

Reproduced on `a_typed_open_reports_the_header_deadline_that_stopped_it` by giving it an
already-expired deadline: the process ran until killed, `sample` showing the test thread in
`JoinHandle::join` (stream_deadline_connect_tests.rs:68) and its server thread in
`TcpListener::accept` (:47).

Every accept that a spawned or scoped test server makes now goes through `plx_base::testnet`:

* `testnet::accept_client(listener, wait)` is new: `accept_within` for a server that cannot go on
  without its client, which panics ("its client never arrived", naming the listener) after `wait`, so
  the thread ends and whoever joins it fails. A scoped server over borrowed state, or a fixture that
  keeps its listener for a second look, cannot hand its listener to `serve_once`; `serve_once` itself
  now accepts through it. `one_shot_server`, `one_shot_echo`, the redirect and User-Agent hop servers,
  and the easy-path `sent`/`served` doubles are `serve_once` (the first two also bound their request
  read); the chunked-drain and keep-alive scope servers (which also bound their reads: `HttpStream` has no
  `Drop`, so a client that panics leaves its socket open and a server parked in `read` would hold the
  scope for ever), `Scripted` (whose `Drop` joined its accept
  unbounded) and the interruptible-open test's peer use `accept_client`; `with_keepalive_listener`'s
  polling acceptor accepts through `testnet::accept`, so its sockets block on Darwin as on Linux.
* The two deadlines that raced a dial no longer do. `a_typed_open_reports_the_header_deadline_...`
  (80 ms) and `continue_slices_neither_end_an_open_early_nor_spin` (300 ms) take
  `testnet::LOOPBACK_DEADLINE` (2 s), far above any delay a loaded host adds to a loopback connect and
  under the 15 s `MEDIA_RECV_TIMEOUT_MS` inactivity budget, past which the CALLER would no longer own
  the instant. Each keeps its intent: the silent peer is still stopped by the caller's timer (graded
  against `LOOPBACK_DEADLINE / 2 ..< MEDIA_RECV_TIMEOUT_MS`), and the checkpoint slice count is graded
  against the span waited (`5 ..= 2 * deadline/slice`) instead of 15 slices over 300 ms.

Not changed, on purpose: accepts that cannot block (the same thread already connected, or a
nonblocking listener asked "did anybody dial?"), the detached `incoming()` loops of net.rs's TLS
doubles (no test joins them) and the polling acceptors that already carry a stop flag and a bound.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit ba276e9 into main Nov 4, 2026
20 checks passed
@GLinnik21
GLinnik21 deleted the fix/plx-net-test-accept branch November 4, 2026 18:37
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