Repository navigation
Bound every plx_net test server's accept, and give its deadlines room - #1232
Merged
Merged
Conversation
#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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What failed
plx_net's test servers can hang the suite the wayplx_plex's did (#1229). A fixture thread blocks inTcpListener::accept()for a client the test under it may never send, and the test'sjoin()(or a fixture'sDrop) then waits for ever on a thread nobody will wake.http_open_until_resultreturnsDeadlinewithout 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 firstconnectleaves the server'sacceptwith no client. A run that should have failed hangsmake checkinstead.It happens on this Mac, without a scratch edit: the unmodified
plx_nettest binary, run under 30yesCPU 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'sDropjoined 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 namedstream_deadline_connect_tests.rs:47(80 ms) andstream_test_support.rs::one_shot_server; the triage below covers everyaccept()inrust-modules/net/src.Fix
plx_base::testnet::accept_client(listener, wait)(new):accept_withinfor a server that cannot go on without its client; it panics ("its client never arrived", naming the listener) afterwait, so the thread ends and whoever joins it fails.serve_oncenow accepts through it. Two newtestnettests pin it.plx_netgoes throughtestnet:serve_onceforone_shot_server,one_shot_echo, the redirect and User-Agent hop servers and the easy-pathsent/serveddoubles (the first two also bound their request read);accept_clientfor the chunked-drain and keep-alive scope servers,Scriptedand the interruptible-open peer. Those scope servers and the two one-shot fixtures also get aCLIENT_WAITread timeout:HttpStreamhas noDrop, so a client that panics leaves its socket open and a server parked inreadwould hold the scope for ever (found in review).with_keepalive_listener's polling acceptor accepts throughtestnet::accept(Darwin accepted sockets become blocking, as on Linux).testnet::LOOPBACK_DEADLINE(2 s), above any delay a loaded host adds to a loopback connect and under plx_net's 15 sMEDIA_RECV_TIMEOUT_MSinactivity 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, gradedLOOPBACK_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/srcstream_test_support.rsone_shot_server,one_shot_echoserve_oncestream_redirect.rs:579,stream_user_agent_tests.rs:53,net_wire_characterization_tests.rs:39(sent),net_response_header_tests.rs:73(served)serve_oncestream_chunked_drain_tests.rsx7,stream_keepalive_reuse_tests.rsx4 (first accept of each server)accept_clientstream_checkpoint_tests.rs:45(Scripted)finishandDrop:accept_clientstream_deadline_connect_tests.rs:47(typed open),:251(interruptible open)serve_once/accept_clientstream_test_support.rs:241(with_keepalive_listener)testnet::acceptstream_deadline_connect_tests.rs:202,stream_ipv6_resolution_tests.rs:282connectcompleted: cannot block, unchangedstream_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:131net.rsincoming()loops (1254, 1497, 1550, 1618)net.rs:4078,:4381testnet::acceptwith a stop flag/bound: unchangednet/h2_reset_fixture.py:56listener.settimeout(10): unchangedNot changed, and still able to hold a failing run: the
std::sync::Barrierwaits 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
a_typed_open_reports_the_header_deadline_that_stopped_itan 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.sampleof the stuck binary: test thread inJoinHandle::join(stream_deadline_connect_tests.rs:68), server thread inTcpListener::accept(:47).FAILED ... finished in 10.00s,loopback server: its client never arrived: no client reached 127.0.0.1:<port> within 10s.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.yes > /dev/nullhogs from a script with an EXIT trap, checked afterwards: noyessurvives;perl -e 'alarm shift; exec @ARGV' SECSper run):plx_nettest 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).make check(committed tree, cleangit status), on this Mac:plx_net(test result: ok. 213 passed) andplx_base(test result: ok. 247 passed, with the two newtestnettests).==== 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_plexhttp::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 istestnet's bound doing its job on a stalled client) andplex::session::persistence::db8_policy_tests::arm_candidate_assembly_puts_the_canonical_wrapper_first;plx_mediaff::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 earliermake checkruns of this tree) andff::stall_guard_tests::a_hold_accepted_during_a_blocked_body_read_ends_that_read. This branch changes no file inplx_plex,plx_mediaorplx_session.🤖 Generated with Claude Code