Skip to content

Pull legs run on ephemeral per-serve runtimes, stranding shared connection drivers (HTTP + QUIC) #1675

Closed

Description

@alpergundogdu

Summary

Serve-miss pull legs run on ephemeral, per-serve current-thread runtimes that the orchestration drops the instant a serve finishes. Those runtimes own long-lived connection driver tasks (a task cannot outlive its runtime), so a connection first driven on one serve's runtime is stranded when that runtime is dropped — breaking a concurrent serve that shares it. We have now hit this on two transports, patched each locally. This issue tracks the real fix: give pull legs a stable, long-lived runtime so connection drivers never die mid-serve.

Why the per-serve runtime exists

decdn_client_pull::drive's fill future is !Send (the IngestStore fill is deliberately non-Send), which the iroh ProtocolHandler::accept bound forbids on the serve/accept task. So serve_via_window_pull_through / serve_via_backend_origin (crates/node/src/handlers/client/window.rs) each spawn a fresh OS thread with its own new_current_thread runtime and block_on the pull leg there. That runtime is dropped when the pull returns and the thread closure ends.

The two instances

  1. HTTP origin (own-origin pull) — Flaky serve-miss coalescing tests under CI coverage contention (early-eof / peer hang, B3 #1656) #1673, fixed in this PR.
    HttpOrigin (crates/cache/src/origin/http.rs) holds ONE shared reqwest::Client (cloned across serves). reqwest's per-host idle keep-alive pool binds a connection's hyper dispatch task to the runtime that opened it. Two concurrent disjoint own-origin serves shared a pooled connection; when the first finished and its runtime dropped, the second's in-flight GET failed with client error (SendRequest): dispatch task is gone: runtime dropped the dispatch task, which the paying client saw as read frame: early eof. CI coverage-starvation widened the drop-while-in-flight window (CI-only flake).
    Workaround: pool_max_idle_per_host(0) — no idle connection is retained, so none is reused across runtimes. Correct, but gives up origin keep-alive (fresh TCP+TLS per request).

  2. QUIC upstream (peer pull) — the "abandon drain".
    run_pull_leg (crates/node/src/node_origin/pull_leg.rs) already documents the same disease: a cancelled/errored drive leaves the upstream iroh connection's QUIC driver on the ephemeral runtime, which the caller drops immediately, so the CONNECTION_CLOSE is never flushed and Endpoint::close() could hang forever. Workaround: a fixed ABANDON_DRAIN sleep before returning, to let the connection flush on the runtime that owns it.

Both are point patches for the same architectural smell.

Proposed direction

Run pull legs on a single, long-lived runtime (or a small pool) owned for the node's lifetime, instead of a throwaway runtime per serve. Because drive is !Send, the natural shape is a dedicated current-thread runtime on its own thread that all pull legs are dispatched onto (e.g. via a LocalSet / an mpsc of boxed !Send local jobs constructed on that thread), rather than N ephemeral runtimes. With a stable runtime:

  • the reqwest connection pool (and any iroh connection driver) lives as long as the node, so no mid-serve teardown strands anyone — we can restore origin keep-alive (drop pool_max_idle_per_host(0));
  • the QUIC abandon-drain sleep can likely be removed too;
  • coalescing/lease/set_pull_handle join semantics need re-thinking (today the last-out observer joins the pull thread; with a shared runtime there is no per-pull thread to join — cancellation + completion signalling via FillSession still applies).

Alternatives considered and rejected for now: per-pull-leg reqwest::Client (isolates HTTP but not the general problem, and doesn't help QUIC); keeping per-serve runtimes but never sharing anything across them (fragile, easy to regress).

Not urgent

The two local workarounds are correct and low-cost at current scale (own-origin pulls fetch few, large ranges, so per-request handshake overhead amortizes). This is a cleanup/robustness item, not a live defect. Filing so the shared root cause is tracked rather than rediscovered on a third transport.

Acceptance

  • Pull legs no longer run on runtimes that are dropped mid-connection-lifetime.
  • pool_max_idle_per_host(0) and the ABANDON_DRAIN sleep can both be removed with the disjoint-serve and endpoint-close no-hang tests still green.

References

Activity

  1. added
    rust
    prio:low
    on Aug 20, 2026
  2. moved this from Backlog to Needs Decision in deCDNon Aug 20, 2026
  3. moved this from Needs Decision to Backlog in deCDNon Aug 20, 2026
  4. thiras commented on Aug 24, 2026

    @thiras
    Contributor

    Counter-evidence for the "Not urgent … not a live defect" framing: the QUIC half of this (the ABANDON_DRAIN workaround) is currently the single reason the test job goes red on main.

    Three runs, two of them on main with no PR involved, all with decdn-node::node_origin_pull::a_wedged_channel_open_does_not_starve_the_candidate_loop burning the full 300 s nextest backstop while every other test passes:

    Filed as #1779 with the detail. One finding there is relevant to the acceptance criteria here: the test-side stopgap from #1718 is in place and fires (shutdown: endpoint close timed out after 10s (0/4 drained)), yet the test still runs the full 300 s — so bounding Endpoint::close() relocated the wedge rather than removing it. The stable-runtime work proposed here looks like the actual fix.

  5. yigitdot commented on Aug 26, 2026

    @yigitdot
    Contributor

    Concrete sighting from the warn channel this issue relies on, recorded while working #1830.

    Running cargo nextest run --workspace --no-fail-fast locally (14-core darwin, no coverage instrumentation), support::shutdown reports the stranded-driver signature on:

    decdn-node::node_origin_pull node_origin_pull_falls_through_a_stalled_candidate
        shutdown: teardown exceeded 15s (1/1 tasks reaped, 0/2 endpoints closed)
    

    0/M endpoints closed after the tasks reaped cleanly is the Endpoint::close() half — the abandoned upstream connection's QUIC driver never forwarded the endpoint's draining event, exactly the mechanism described in the issue body. The test deliberately stalls a candidate, so it is a natural producer.

    It is intermittent and contention-dependent: three breaches on one full-workspace run, one on the next, and none on a -p decdn-node-only run. The test passes either way — the breach only warns.

    Worth noting alongside it: #1832 raised support::SHUTDOWN_TIMEOUT from 10s to 15s because it equalled ABANDON_DRAIN_CAP (10s). With the two tied, a single ceilinged abandon drain could consume the whole test teardown budget before the first ep.close() was even attempted, and the warn line would then print 0/M endpoints closed for a run in which nothing was actually stranded. So readings from before that change are ambiguous between "stranded driver" and "ran out of budget getting there"; the sighting above is from after it, and is a true positive.

    No action requested here — filing the observation so this issue has a named reproducer rather than only the counter.

  6. thiras commented on Sep 26, 2026

    @thiras
    Contributor

    Production sighting: SIGTERM never completes, systemd SIGKILLs at the stop cap

    First sighting of this outside CI. On a rolling restart of our 7-node testnet fleet (main @ 3ebf5f17, iroh 1.0.0, systemd KillSignal=SIGTERM, TimeoutStopSec=300), 5 of 7 nodes never finished graceful shutdown and were SIGKILLed at the 300s cap.

    Timeline (2026-09-26, UTC)

    node SIGTERM outcome
    bcl (fs origin) 20:27:07.55 graceful shutdown complete at 20:27:07.83 (0.27s)
    hil1 (near-idle, 22 MB peak RSS) 20:32:10.54 graceful shutdown complete at 20:32:11.14 (0.6s)
    nbg1, hel1, fra1, lon1, ash1 20:27:06–09 never logged past closing router; State 'stop-sigterm' timed out. Killing. at 20:32:06–10

    Journal from one of the stuck nodes (lon1). Nothing between these two groups except multiplexed_poller lines:

    20:27:07 decdn-node: {"message":"shutdown signal received; closing router","signal":"SIGTERM"}
    20:27:07 systemd:    Stopping decdn-node.service ...
    20:32:07 systemd:    decdn-node.service: State 'stop-sigterm' timed out. Killing.
    20:32:07 systemd:    decdn-node.service: Killing process 248144 (decdn-node) with signal SIGKILL.
    20:32:07 systemd:    decdn-node.service: Main process exited, code=killed, status=9/KILL
    20:32:07 systemd:    decdn-node.service: Failed with result 'timeout'.
    

    Where it's stuck

    The chain poller kept logging eth_getLogs window failed; retrying for the full five minutes after SIGTERM (fra1: 20:29:31, 20:31:02, 20:31:32 …). poller.shutdown() is only called after router.shutdown().await returns (crates/node/src/runtime/mod.rs:2589 at 3ebf5f17), so the process was parked inside router.shutdown() for the whole window.

    No decdn ProtocolHandler overrides shutdown(), and iroh 1.0's router cancels the remaining accept futures before its next step. That leaves endpoint.close().await as the only unbounded await, which is the stranded-driver half described in this issue. Nodes that serve from their own origin or see no traffic exited cleanly, and the ones doing cache/peer-pull work hung.

    Caveat: I have no stack from a stuck process, so this is inferred from log ordering rather than proven. Peer-pull activity at INFO level was only visible on 3 of the 5 hung nodes (fra1, lon1, ash1; nbg1 and hel1 had none logged), so INFO logs alone can't confirm or rule out a stranded upstream connection on every hung node. Next time I'll try to capture eu-stack/gdb before the cap.

    Why this is worse in production than in CI

    In CI the breach only warns (support::shutdown teardown budget). In production the hang sits in front of every durability step in shutdown(): the final payment_service.shutdown redeem sweep, the channel_state_store.flush(), the receipt-writer tail flush (#803), the warming-creditor drain and cache.shutdown(). So the supervisor's SIGKILL skips exactly the flushes the generous stop timeout is there to protect. Raising TimeoutStopSec doesn't help because the wait is unbounded, and lowering it only makes the kill come sooner.

    The nodes restarted cleanly afterwards, so nothing visibly broke this time. But every restart of a node carrying a stranded connection currently costs the full stop cap plus a hard kill.

    Until the stable-runtime fix lands, a cheap mitigation would be to bound router.shutdown() with a timeout (as the post-router drain already is with SHUTDOWN_DEADLINE) and warn on overrun. A stranded connection would then only cost the peer a QUIC idle timeout, instead of the node losing its final flushes.

  7. thiras commented on Sep 27, 2026

    @thiras
    Contributor

    A successful pull leg also strands its QUIC driver (abandon_drain.rs "What is not covered"). That has a higher-impact effect now: router.shutdown() → Endpoint::close() → wait_all_draining() waits forever, so every testnet node that finished a node-to-node pull since boot gets SIGKILLed at the 5-min systemd timeout on each deploy. The SIGKILL skips the redeem sweep and the lane-store flush. Tracked in #2185, which also proposes bounding router.shutdown() independently of this fix.

  8. thiras commented on Sep 28, 2026

    @thiras
    Contributor

    The QUIC half of this is resolved by #2187 (closes #2185). Pull legs still run on per-serve current-thread runtimes, but every upstream dial now runs on the node's main runtime (PeerSource::with_dial_runtime + NodeOriginDeps.dial_runtime), so each connection's QUIC driver outlives the leg. The ABANDON_DRAIN wait (the abandon_drain module) and its counter are removed, and router.shutdown() is bounded by SHUTDOWN_DEADLINE.

    Still open here: the HTTP half — pool_max_idle_per_host(0) in crates/cache/src/origin/http.rs. A reqwest keep-alive connection still binds its hyper dispatch task to the per-serve runtime that opened it, so origin keep-alive stays off until pull legs get a long-lived runtime (or HTTP origin fetches move off the pull runtime the same way).

  9. self-assigned this
    on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

prio:lowrust

Type

No type

Fields

Priority

Low

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions