Skip to content

fix(node,client-pull): bound test teardown, observe the abandon drain (#1779) - #1785

Merged
thiras merged 2 commits into
mainfrom
fix/1779-bounded-teardown-deterministic-drain
Aug 24, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/1779-bounded-teardown-deterministic-drain

Conversation

@thiras

@thiras thiras commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Closes #1779.

The 290 s

Not an Endpoint::close() hang. support::shutdown swallowed its 10 s timeout and returned; the test then joined its server accept loops with no bound, and an accept loop exits only once Endpoint::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 on main I caught attack_a_over_market_loss_is_bounded and concurrent_same_lane_misses_refuse_surplus, neither of them the test the issue names.

What changed

Teardown owns itself. shutdown takes [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 reaped vs endpoints closed); a panicking server task is returned, since that is the test's own verdict. reap is the one-shot counterpart for a task that must be joined before its endpoint closes and whose Err is asserted on. ~230 call sites converted.

The concrete JoinHandle<()> is deliberate: a generic JoinHandle<T> would accept the one-shot JoinHandle<anyhow::Result<()>> tasks whose Err several tests assert on, and shutdown would abort them, discarding that verdict silently. The concrete type makes those a compile error — which is how the dht_loopback sites got found.

The drain is observed, not timed. The fixed ABANDON_DRAIN = 3s sleep 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 what close() waits on. So WeakConnectionHandle::upgrade() returning None is drained. Connection::closed() cannot serve — it resolves the instant the local close sets the connection error, before CONNECTION_CLOSE is on the wire.

Observation happens at the dial (PeerSource::with_dial_observer), not on the returned reader: open_stream connects before five post-connect handshake checks that each return with the connection already live, and those are exactly the opens the Err branch then waits on. run_local_pull_leg loses its drain outright — own-origin fetch strands no QUIC driver.

.config/nextest.toml: in-process decdn-node capped at 180 s (from 300 s), plus a separate row for the two anvil-e2e targets — CI runs those under the default profile, so a bare package(decdn-node) override would have killed them against their own 780 s timeout. success-output = "final" so a breach line is actually visible.

Measured

whole binary nextest
main 2 wedges @ 300 s in 20 runs 2 timeouts @ 300 s in ~28 runs
this branch 0 in 25 0 in 15

Forcing the drain cap to zero makes tests fail in ~11 s with teardown exceeded 10s (2/2 tasks reaped, 0/3 endpoints closed) — the 0/N naming 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_bounded was asserting nothing: it slept 300 ms and read an empty progress log, so its spend bound compared 0 <= bound. On main with a 5 s sleep it fails identically. It now waits for the settle; its one_window = CHUNK_BYTES was 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_loop was the only one of 78 tests in its file on a single-threaded runtime, hosting four iroh endpoints. Moving it to multi_thread made it reachable by the known ranking flake (score multiplies rate by live probe RTT), so it now uses build_origin_seeded_ranking.

Scope left open

  • Pull legs run on ephemeral per-serve runtimes, stranding shared connection drivers (HTTP + QUIC) #1675 residual. A teardown breach still happens occasionally under heavy local contention. A bisect — restoring the old fixed sleep on top of this branch — showed the same residual, so it is not caused by this change. It warns rather than failing, because no test here can fix it; decdn_node_pull_abandon_drain_timeout_total carries it in production. The clean-Ok path is in the same class: UpstreamPull::finish closes without awaiting drained, and waiting there would add 3 × PTO to every successful serve-miss teardown.
  • 25 unbounded ep.close().await calls remain in dht_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_channels flakes independently of this work — reproduced on main and with the old sleep restored. Worth its own issue.

Verification

cargo clippy --workspace --all-targets and --all-features clean, cargo fmt --check clean, rustdoc -D warnings clean, cargo nextest run --workspace 2949/2949 (+9 new tests covering abandon_drain, shutdown and reap, including the poison path and a real loopback connection pinning the ceiling).

🤖 Generated with Claude Code

https://claude.ai/code/session_01JjiDQL7FuB8UHGBBpG1PjH

thiras and others added 2 commits August 24, 2026 07:36
…#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
Copilot AI lite review requested due to automatic review settings August 24, 2026 10:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 reap helper for one-shot tasks whose Err is 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-node while 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.

@github-actions

Copy link
Copy Markdown

Coverage report

Total: 81.62% (was 81.60%, ▲ +0.02%) — 64977/79605 lines

File Coverage Lines Δ
crates/cli/src/commands/fetch.rs 34.52% 522/1512 ▼ 0.09%
crates/client-pull/src/lib.rs 89.15% 1660/1862 ▲ +0.06%
crates/client-pull/src/source.rs 92.84% 311/335 ▲ +0.13%
crates/node/src/metrics.rs 94.46% 852/902 ● 0.00%
crates/node/src/node_origin/abandon_drain.rs 94.53% 121/128 new
crates/node/src/node_origin/mod.rs 91.30% 1133/1241 ▲ +0.04%
crates/node/src/node_origin/pull_leg.rs 85.61% 577/674 ▲ +0.02%
History
Commit Total Δ vs base
6e94ace (HEAD) 81.62% ▲ +0.02%

@thiras
thiras merged commit bf45319 into main Aug 24, 2026
26 checks passed
@thiras
thiras deleted the fix/1779-bounded-teardown-deterministic-drain branch August 24, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants