Repository navigation
fix(node,client-pull): bound test teardown, observe the abandon drain (#1779) - #1785
Merged
Merged
Conversation
…#1779) `node_origin_pull` intermittently burned the full 300s nextest backstop and reddened `test` on `main`. The wedge is an unbounded join: `support::shutdown` swallowed its 10s timeout and returned, and the test then joined its server accept loops with no bound. Those loops exit only once `Endpoint::close()` completes, so a stranded endpoint parked the test until SIGKILL — 300s minus the 10s teardown, to the second. The shape was suite-wide, which is why the victim was a different arbitrary test each time. `shutdown` now owns the whole teardown and nothing in it is unbounded: abort, reap, close, under one deadline. Reaping between the abort and the close matters — `abort()` only schedules cancellation, so a close starting before the task's future is dropped still finds a handler holding a connection open. A breach warns and names the stage it stalled in (`tasks reaped` vs `endpoints closed`); a panicking server task is returned, since that is the test's own verdict and the only channel a handler panic has. `reap` is the one-shot counterpart for a task that must be joined before its endpoint closes and whose `Err` is asserted on. The abandoned pull leg now waits for its upstream connection to actually reach drained instead of sleeping a fixed 3s. The quantity that sleep had to cover is QUIC's close timer, `3 * PTO`, derived from live RTT samples — under CPU starvation it exceeds any constant, which is how the connection got stranded. `WeakConnectionHandle::upgrade()` returning `None` is the transition: the connection driver holds the last strong reference and releases it on the poll that forwards the endpoint's draining event, which is what the close waits on. `Connection::closed()` cannot serve — it resolves the instant the local close sets the connection error. `run_local_pull_leg` loses its drain outright: it fetches from the node's own origin and strands no QUIC driver. `decdn_node_pull_abandon_drain_timeout_total` counts a connection still held at the ceiling — one this node is about to strand. Also fixes two latent test defects the faster settle exposed: `window_pull_through_underpaid_voucher_abandons_bounded` slept 300ms and read an empty progress log, so its spend bound asserted `0 <= bound` and proved nothing; it now waits for the settle and bounds against `PULL_WINDOW_FLOOR` converted to wire bytes, rather than a bare `CHUNK_BYTES` that never was the floor. And `a_wedged_channel_open_does_not_starve_the_candidate_loop` was the only one of 78 tests in its file on a single-threaded runtime, hosting four iroh endpoints. Measured over 20 whole-binary runs each: 2 wedges at 300s on `main`, 0 on this branch; under nextest, `main` timed out at 300s twice in ~28 runs and this branch not once in 40. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01JjiDQL7FuB8UHGBBpG1PjH
…teardown joins Review follow-up to the #1779 work. The largest finding is a regression the first cut introduced. **The drain missed every connection whose open failed.** `ObservedPeerSource` recorded a connection by reaching through the reader that `BlobSource::open` returns — so it saw nothing when `open` itself failed, and `open_stream` dials before five post-connect handshake checks (refusal, redirect, over-ceiling size, over-ceiling rate, resume offset past end) that each return with the connection already live on the pull runtime. Those are exactly the opens the `Err` branch then waits on, and the wait found an empty record and returned at once. The deleted fixed sleep had covered them unconditionally. The observation moves to the dial: `PeerSource::with_dial_observer` takes a `DialObserver` that `open_stream` notifies the instant `connect` returns, before any step that can fail. That is strictly earlier than the old sleep covered, and it collapses the node-side decorator and `PullReader::connection_handle` — neither is needed once the source records for itself. The publisher CLI passes `None` and pays nothing. **`all_drained` did the opposite of its docstring.** `Result::is_ok_and` is `false` on `Err`, so a poisoned lock reported NOT drained — a full ten-second stall and a false stranded-connection metric, where the doc promised the opposite. Both accessors now read through the poison with `PoisonError::into_inner`, the convention already used in this suite: the guarded value is a `Vec` of weak handles with no invariant a panic can break, so neither fail direction was ever the right answer. `wait_drained` returns the count still held rather than a bool, so the counter ticks once per stranded connection — a leg opens one per gap. **The claims that were not true.** `shutdown`'s docstring asserted nothing in the suite was unbounded while sixteen hand-rolled joins still were, six of them under comments this branch had just added; they now route through `shutdown`/`reap`. The nextest comment said a breach fails, when it warns. The breach line was written to a stream nextest discards for a passing test, so the visibility the warn-not-fail trade depends on did not exist — `success-output = "final"` restores it. The clean-`Ok` path was called safe: `UpstreamPull::finish` closes without awaiting drained, so it carries the same residual as #1675 and now says so. `OpenSlotReserved` and `record_channel_open_failure` survived the rename sweep in two files. `reap` detached a parked task instead of aborting it, so the next teardown paid the deadline again. `abandon_drain` and the teardown helpers now carry their own tests — nine, cheap, including the poison path that hid the inverted branch and a real loopback connection that pins the ceiling. `a_wedged_channel_open_does_not_starve_the_candidate_loop` moves to seeded ranking. On multi_thread its live probe RTTs vary enough that a wedged node can rank behind the pricier honest one, and only one wedged open is tried — the ranking flake `build_origin_seeded_ranking` exists for. Measured after: 25/25 clean whole-binary runs and 15/15 clean nextest runs, against 3/20 before. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01JjiDQL7FuB8UHGBBpG1PjH
There was a problem hiding this comment.
Pull request overview
This PR addresses intermittent 300s nextest timeouts in decdn-node tests by ensuring teardown is fully bounded and by replacing the fixed “abandon drain” sleep with an observed drain signal for upstream QUIC connections on abandoned pull legs.
Changes:
- Reworks test teardown helpers to abort → reap → close under a single deadline, and introduces a bounded
reaphelper for one-shot tasks whoseErris asserted. - Implements observed abandon-drain tracking by recording dialed connections and waiting for them to reach drained (via weak-handle upgrade) under a cap, instead of sleeping a fixed duration.
- Tightens nextest per-test caps for
decdn-nodewhile carving out longer limits for anvil-backed e2e binaries, and ensures successful tests still emit final output.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/tests/support/mod.rs | Makes teardown bounded under one shared timeout; changes shutdown to own JoinHandle<()> and adds reap for one-shot joins. |
| crates/node/tests/support_teardown.rs | Adds dedicated tests that pin shutdown/reap semantics (timeouts, panic surfacing, “first fault” behavior). |
| crates/node/tests/probe_loopback.rs | Migrates teardown to shutdown(...).await? and uses reap where a one-shot accept task must be joined. |
| crates/node/tests/origin_range_pull.rs | Switches teardown to shutdown([server_task], ...) so accept loops are reaped under the shared deadline. |
| crates/node/tests/node_to_node_pull_through.rs | Consolidates teardown into shutdown([...tasks...], [...endpoints...]) and uses reap for bounded joins when needed. |
| crates/node/tests/node_origin_pull.rs | Updates many teardowns to the new shutdown signature; fixes underpaid-voucher test to wait for settle and uses correct window floor; adjusts runtime flavor for the historically flaky test. |
| crates/node/tests/dht_loopback.rs | Replaces unbounded joins with reap and routes endpoint closure through the bounded teardown helpers. |
| crates/node/tests/client_loopback.rs | Consolidates endpoint close + server-task join into bounded shutdown([server_task], ...) patterns. |
| crates/node/src/node_origin/pull_leg.rs | Replaces fixed abandon-drain sleep with observed drain via ConnDrain + dial observer; removes drain for local/origin pull leg. |
| crates/node/src/node_origin/mod.rs | Wires dial observation into candidate pulls and uses observed drain wait on cancel/Err paths. |
| crates/node/src/node_origin/abandon_drain.rs | Adds the observed abandon-drain implementation (weak-handle tracking, bounded poll, metric + warn on cap). |
| crates/node/src/metrics.rs | Adds node_pull_abandon_drain_timeout counter with detailed operational meaning and recorder wiring. |
| crates/client-pull/src/source.rs | Adds optional per-dial observer plumbing in PeerSource and passes it through to open_progressive_pull. |
| crates/client-pull/src/lib.rs | Introduces DialObserver and threads it into open_stream/open_progressive_pull so callers can observe dials before handshake failures. |
| crates/cli/src/commands/fetch.rs | Passes None for the new dial observer parameter (CLI uses a long-lived runtime). |
| .config/nextest.toml | Adds targeted overrides: shorter cap for in-process decdn-node, separate longer cap for anvil e2e binaries, and success-output = "final". |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 81.62% (was 81.60%, ▲ +0.02%) — 64977/79605 lines
History
|
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.
Closes #1779.
The 290 s
Not an
Endpoint::close()hang.support::shutdownswallowed its 10 s timeout and returned; the test then joined its server accept loops with no bound, and an accept loop exits only onceEndpoint::close()completes. 300 − 10, to the second. The shape was suite-wide, which is why the victim was a different arbitrary test each run — reproducing onmainI caughtattack_a_over_market_loss_is_boundedandconcurrent_same_lane_misses_refuse_surplus, neither of them the test the issue names.What changed
Teardown owns itself.
shutdowntakes[JoinHandle<()>; N], and does abort → reap → close under one deadline with nothing unbounded. Reaping between the abort and the close is the load-bearing part:abort()only schedules cancellation, so a close starting before the task's future is dropped still finds a handler holding a connection open. A breach warns and names the stage (tasks reapedvsendpoints closed); a panicking server task is returned, since that is the test's own verdict.reapis the one-shot counterpart for a task that must be joined before its endpoint closes and whoseErris asserted on. ~230 call sites converted.The concrete
JoinHandle<()>is deliberate: a genericJoinHandle<T>would accept the one-shotJoinHandle<anyhow::Result<()>>tasks whoseErrseveral tests assert on, andshutdownwould abort them, discarding that verdict silently. The concrete type makes those a compile error — which is how thedht_loopbacksites got found.The drain is observed, not timed. The fixed
ABANDON_DRAIN = 3ssleep is gone. What it had to cover is QUIC's close timer,3 × PTO, derived from live RTT samples — under CPU starvation that exceeds any constant, which is how the connection got stranded. The transition itself is observable: the connection driver holds the last strong reference and releases it on the same poll that forwards the endpoint's draining event, which is whatclose()waits on. SoWeakConnectionHandle::upgrade()returningNoneis drained.Connection::closed()cannot serve — it resolves the instant the local close sets the connection error, beforeCONNECTION_CLOSEis on the wire.Observation happens at the dial (
PeerSource::with_dial_observer), not on the returned reader:open_streamconnects before five post-connect handshake checks that each return with the connection already live, and those are exactly the opens theErrbranch then waits on.run_local_pull_legloses its drain outright — own-origin fetch strands no QUIC driver..config/nextest.toml: in-processdecdn-nodecapped at 180 s (from 300 s), plus a separate row for the twoanvil-e2etargets — CI runs those under the default profile, so a barepackage(decdn-node)override would have killed them against their own 780 s timeout.success-output = "final"so a breach line is actually visible.Measured
mainForcing the drain cap to zero makes tests fail in ~11 s with
teardown exceeded 10s (2/2 tasks reaped, 0/3 endpoints closed)— the0/Nnaming the close stage. That proves both the bound fires and the drain is load-bearing.Latent defects this exposed
window_pull_through_underpaid_voucher_abandons_boundedwas asserting nothing: it slept 300 ms and read an empty progress log, so its spend bound compared0 <= bound. Onmainwith a 5 s sleep it fails identically. It now waits for the settle; itsone_window = CHUNK_BYTESwas never the floor (PULL_WINDOW_FLOOR = CHUNK_BYTES + 2 × CHUNK_GROUP_BYTES), and the node pulls exactly that, to the byte. No product bug.a_wedged_channel_open_does_not_starve_the_candidate_loopwas the only one of 78 tests in its file on a single-threaded runtime, hosting four iroh endpoints. Moving it tomulti_threadmade it reachable by the known ranking flake (score multiplies rate by live probe RTT), so it now usesbuild_origin_seeded_ranking.Scope left open
decdn_node_pull_abandon_drain_timeout_totalcarries it in production. The clean-Okpath is in the same class:UpstreamPull::finishcloses without awaiting drained, and waiting there would add3 × PTOto every successful serve-miss teardown.ep.close().awaitcalls remain indht_bootstrap.rs,dht_lookup.rs,dht_integration.rs,probe_warm_reconnect.rs. Same hazard, but those files have their own teardown helpers with deliberate semantics (one awaits the close so the peer is genuinely unreachable), and converting blind would change what they test.concurrent_pulls_resume_at_their_own_frontier_not_the_channelsflakes independently of this work — reproduced onmainand with the old sleep restored. Worth its own issue.Verification
cargo clippy --workspace --all-targetsand--all-featuresclean,cargo fmt --checkclean, rustdoc-D warningsclean,cargo nextest run --workspace2949/2949 (+9 new tests coveringabandon_drain,shutdownandreap, including the poison path and a real loopback connection pinning the ceiling).🤖 Generated with Claude Code
https://claude.ai/code/session_01JjiDQL7FuB8UHGBBpG1PjH