Repository navigation
Bound every plx_plex test server's accept, and give its deadlines room - #1229
Merged
Merged
Conversation
`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
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]>
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 hung
make check's cargo stage hung for about an hour, twice. Asampleof the stuckplx_plextest binary showed:plx_plex::http::tests::a_completed_500_cannot_become_a_deadline_after_the_caller_crosses_the_boundary(http.rs) blocked inJoinHandle::join(server.join());TcpListener::accept().Root cause
The test gives
request_until_outcomea 250 ms caller deadline.request_withchecks the clock before it opens a socket and returnsDeadlinewithout dialing once the deadline has passed. On a loaded host (the python half ofmake checkruns beside the cargo half) the client can reach 250 ms before its firstconnect. Nobody connects, the server thread's blockingaccept()never returns, andjoin()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, andclient.rs'smalformed_2xx_...with an inlined copy ofcross).Fix
plx_base::testnetis already the repo's single fixture accept andplx_plexalready used it, so it gains the bounded forms instead of a helper private tohttp.rs(five files needed it):accept_within(listener, wait): polls a nonblocking listener, returns aTimedOuterror naming the listener if nobody connects, and still hands back a blocking socket (the Darwin fixtestnet::acceptexists for).serve_once(listener, wait, serve): spawns the server thread; if no client arrives it panics with "its client never arrived", so the test'sjoin()fails afterCLIENT_WAIT(10 s) instead of blocking.accept()test server inplx_plexgoes through them:http.rs,plex/notify.rs,plex/client.rs,plex/collections.rs,plex/transcoder.rs. The last three plusclient.rsaredevtriggerstests thatmake test-cratedoes not enable. The two pin tests' stop-flag pollers inhttp.rsget aCLIENT_WAITbound (an assertion failing beforestopwas set left their thread scope joining them for ever). The "must not dial" asserts were never servers and are unchanged.testnet::LOOPBACK_DEADLINE(2 s). It is far above any scheduling delay on a millisecond loopback exchange, and belowplx_net's 15 smedia_stall_budget(): past that,request_until_outcomereads an expiry as the transport's liveness (Transport(None)), not the caller'sDeadline, 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 withclient.rs, replacing its inline copy) sleeps out the 2 s, so the 500 and reset tests (andmalformed_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), andan_expired_caller_deadline_is_a_deadline_without_dialing_and_a_bounded_accept_says_soinhttp.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) undermake 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.sampleshowed the test thread instd::thread::JoinHandle::join(http.rs:1260) and the server thread athttp.rs:1247(accept).Reproduction (after): the same scratch edit on the fixed code fails after 10.00 s with:
Tests:
make test-crate C=plx_base T=testnet:test result: ok. 4 passed; 0 failedmake test-crate C=plx_plex:test result: ok. 768 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 9.91scargo test --lib -p plx_plex --features devtriggers(compiles and runs the gatedclient.rs,collections.rs,transcoder.rstests):test result: ok. 768 passed; 0 failedUnder load: the affected tests run 30 times each with 20
yesCPU hogs on 10 cores (killed by atrap). Default features, filtershttp::tests plex::notify: 30/30 iterationsok. 53 passed; 0 failed. With--features devtriggersaddingmalformed_2xx transcode_ resource_close mde_never authorization_and_absence: 30/30 iterationsok. 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 checkon the committed tree (cleangit status --shortbefore and after), exit 0:Not in this PR
The same blocking-
accept()shape exists inplx_net's test fixtures (stream_deadline_connect_tests.rs:47with an 80 ms deadline,stream_test_support.rs::one_shot_serverused bystream_header_body_tests.rs:310with 250 ms, and others).http_open_with_timeoutsalso returnsDeadlinebefore dialing, so they can hang the same way. They are the same migration ontotestnet::serve_once; left for a follow-up to keep this PR toplx_plex.🤖 Generated with Claude Code