Skip to content

fix(node,client): dial pull-leg upstreams on the main runtime so SIGTERM never hangs - #2187

Merged
thiras merged 2 commits into
mainfrom
fix/2185-dial-on-main-runtime
Sep 28, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/2185-dial-on-main-runtime

Conversation

@thiras

@thiras thiras commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

What

decdn-node hung in router.shutdown() on SIGTERM on every node that had done a node-to-node pull since boot, until systemd SIGKILLed it at the 5-minute stop timeout — skipping the final redeem sweep, lane-store flush, receipt tail and cache.shutdown.

Root cause: serve-miss pull legs run on a throwaway current-thread runtime. An upstream dial made there spawned the connection's noq ConnectionDriver on that runtime; when the leg returned the runtime dropped, the driver died before the connection reached draining, and iroh's Endpoint::close → wait_all_draining() waited forever. The old abandon-drain wait covered only the cancel/error paths, so its counter read a false zero.

  • Root fix (decdn-client): connection::dial runs the connect on a caller-chosen runtime — abort-on-drop, instrumented with the caller's span; a dial task that panics or is cancelled by its runtime shutting down is a LocalPullFault, never the peer's. PeerSource::with_dial_runtime(Handle) replaces with_dial_observer/DialObserver; open_progressive_pull and WarmConnection::connect take dial_runtime: Option<&Handle> (public-API snapshot regenerated).
  • Node wiring: NodeOriginDeps.dial_runtime (the main runtime) is used by every PeerSource the node builds, handshakes included. The abandon_drain module, decdn_node_pull_abandon_drain_timeout_total and its two dashboard series are removed.
  • Defence in depth: close_router bounds the router close by SHUTDOWN_DEADLINE and logs an error! when it gives up, so redeem/flush/cache close always run.
  • Tests: test-support shutdown now fails on a teardown breach (it only warned). New tests for the dial (+ strand control), abort-on-drop, dial on a shut-down runtime, warm dial, close_router (+ control), strict teardown. The node_to_node_coalesce e2e now SIGTERMs the server and requires a clean exit with no router give-up line.

Closes #2185

Reviewer notes

  • Start with crates/client/src/connection.rs (dial), then crates/node/src/node_origin/{mod.rs,pull_leg.rs} and close_router in crates/node/src/runtime/mod.rs.
  • This hang was already in CI, silently. In 3 of the last 10 main CI runs, window_pull_through_handshake_is_the_first_pull_leg logged teardown exceeded 15s (… 1/3 endpoints closed) — the success-path strand — and passed because teardown only warned. With this PR it stays clean, and a recurrence now fails. That test also moves to a multi-thread runtime.
  • Each dial site is independently covered: reverting the window-leg dial fails the two window_pull_through_* error-path tests; reverting the populate-thread dial fails node_origin_oversized_blob_aborts_on_received_bytes_without_scoring.
  • Known limit: the success-path strand is timing-dependent. The e2e SIGTERM stage passes even with the fix reverted (the harness never strands a clean pull), so it pins the real shutdown path and router bound, not the bug itself. The final testnet check is systemctl stop decdn-node on fra1/lon1 after deploy.
  • Making teardown breaches fatal also makes "task outlived its abort" fatal — intended; a full node suite run with the fix had no breach outside the two deliberate support_teardown cases, and three oversubscribed runs (32 threads) of the teardown-heavy suites were clean.
  • The reqwest keep-alive half of Pull legs run on ephemeral per-serve runtimes, stranding shared connection drivers (HTTP + QUIC) #1675 (cache/src/origin/http.rs) is untouched and stays open.

Verification

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets -- -D warnings (clean). Not run with --all-features: the anvil-e2e targets carry pre-existing warnings; the files this PR touches under that feature (crates/e2e/src/node.rs, node_to_node_coalesce.rs) lint clean.
  • cargo nextest run --workspace — 4149 passed
  • cargo nextest run -p decdn-client --features public-api-test --test public_api — passed (snapshot regenerated)
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items
  • cargo nextest run -p decdn-e2e --features anvil-e2e --test node_to_node_coalesce — passed (server stops in ~100 ms)
  • User-visible change: CHANGELOG.md entries added (Fixed + Changed (BREAKING) for the decdn-client API)
  • contracts/ changed — n/a
  • Design change: ADR — n/a (no ADR described the abandon drain or its metric)
  • PR title uses fix with a lowercase subject

🤖 Generated with Claude Code

…ERM never hangs

A serve-miss pull leg runs on a throwaway current-thread runtime. An
upstream dial made there spawned the connection's QUIC driver on that
runtime, which dropped with the leg, so the connection never reached
draining and `Endpoint::close` parked `router.shutdown()` until systemd
SIGKILLed the node, skipping the redeem sweep, lane flush, receipt tail
and cache close.

- decdn-client: `connection::dial` runs the connect on a caller-chosen
  runtime (abort-on-drop, span-instrumented; a panicked or cancelled dial
  task is a `LocalPullFault`). `PeerSource::with_dial_runtime` replaces
  `with_dial_observer`/`DialObserver`; `open_progressive_pull` and
  `WarmConnection::connect` take `dial_runtime`.
- decdn-node: `NodeOriginDeps.dial_runtime` (the main runtime) is used by
  every `PeerSource` the node builds. The abandon-drain wait, its counter
  `decdn_node_pull_abandon_drain_timeout_total` and its dashboard series
  are removed. `close_router` bounds the router close by
  `SHUTDOWN_DEADLINE` and logs an error when it gives up.
- tests: test-support `shutdown` fails on a teardown breach (it only
  warned, which hid this hang in CI); new dial / close_router / strict
  teardown tests; the node-to-node e2e now SIGTERMs the server.

Closes #2185

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 27, 2026 23:37
@thiras thiras self-assigned this Sep 27, 2026

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.

Copilot review overview

🟡 Changes recommended

Two unresolved moderate findings must be addressed before approval.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes node shutdown hangs by routing upstream dials to the main runtime and bounding router shutdown.

Changes:

  • Adds caller-selected dial runtimes and updates the client API.
  • Removes abandon-drain handling and metrics.
  • Strengthens teardown checks and adds SIGTERM regression coverage.

Review findings:

  • Moderate: the e2e log assertion may pass before detached tee threads flush the router-timeout error (4 votes).
  • Moderate: router-close failures no longer have a replacement metric or dashboard signal (1 vote).
File Summary
monitoring/​grafana-dashboard.json Removes obsolete drain metric panel.
monitoring/​dashboard-delivery.json Removes obsolete drain metric panel.
crates/​node/​tests/​support/​mod.rs Makes teardown breaches fatal.
crates/​node/​tests/​support_teardown.rs Adds strict teardown tests.
crates/​node/​tests/​probe_loopback.rs Restores real-time teardown clocks.
crates/​node/​tests/​node_origin_pull.rs Updates dial runtime usage.
crates/​node/​tests/​dht_integration.rs Uses strict endpoint teardown.
crates/​node/​tests/​client_loopback.rs Updates warm connection API usage.
crates/​node/​src/​runtime/​mod.rs Adds bounded router shutdown.
crates/​node/​src/​node_origin/​pull_leg.rs Routes pull-leg dials to the main runtime.
crates/​node/​src/​node_origin/​mod.rs Wires the main runtime dependency.
crates/​node/​src/​node_origin/​abandon_drain.rs Removes obsolete drain workaround.
crates/​node/​src/​metrics.rs Removes obsolete drain counter.
crates/​e2e/​tests/​node_to_node_coalesce.rs Adds SIGTERM shutdown coverage.
crates/​e2e/​src/​node.rs Adds daemon termination support.
crates/​e2e/​Cargo.toml Adds signal dependency.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Regenerates the public API snapshot.
crates/​client/​src/​source.rs Stores and propagates the dial runtime.
crates/​client/​src/​lib.rs Updates pull dial plumbing.
crates/​client/​src/​connection.rs Implements runtime-bound dialing.
CHANGELOG.md Documents runtime and API changes.
Cargo.lock Updates dependency metadata.
.config/​nextest.toml Updates teardown documentation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-code-quality

github-code-quality Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit f69b7e3 in the fix/2185-dial-on-mai... branch remains at 86%, unchanged from commit af5a682 in the main branch.

Show a line coverage summary of the most impacted files.
File main af5a682 fix/2185-dial-on-mai... f69b7e3 +/-
crates/e2e/src/node.rs 42% 39% -3%
crates/client/s...c/connection.rs 100% 97% -3%
crates/incentiv...eth_identity.rs 99% 98% -1%
crates/node/src...gin/pull_leg.rs 89% 89% 0%
crates/node/src...s/client/mod.rs 96% 96% 0%
crates/cache/src/engine.rs 94% 94% 0%
crates/client/src/scheduler.rs 95% 95% 0%
crates/client/src/lib.rs 92% 92% 0%
crates/node/src...e_origin/mod.rs 92% 92% 0%
crates/node/src/runtime/mod.rs 50% 51% +1%

Updated September 27, 2026 23:54 UTC

…ate returns

The stdout/stderr tee threads were detached, so a child's exit did not
order its last lines into the captured log: the SIGTERM stage's negative
check for a router give-up line could read the log before the line
landed. `DaemonLog` now keeps its reader handles, and
`NodeFixture::terminate` returns only once both have read to EOF.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras

thiras commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

On the overview's second finding ("router-close failures no longer have a replacement metric or dashboard signal"): leaving this as a log line on purpose. close_router gives up only during shutdown, immediately before the process exits, so a counter bumped there is never scraped — Prometheus would never see a non-zero value, and a panel on it would read zero whatever happened (the same false-zero problem the removed decdn_node_pull_abandon_drain_timeout_total had). The give-up is logged at error!, which Loki keeps after the process is gone and an error-level alert can match.

@thiras
thiras merged commit 0502e2d into main Sep 28, 2026
32 checks passed
@thiras
thiras deleted the fix/2185-dial-on-main-runtime branch September 28, 2026 00:00
thiras added a commit that referenced this pull request Oct 5, 2026
…estore HTTP keep-alive (#2308)

* fix(cache): run origin request sends on the node's main runtime and restore HTTP keep-alive (#1675)

A serve-miss pull leg runs on its own current-thread runtime, which drops
when the leg returns. hyper spawns a pooled connection's dispatch task, its
pool-return task and the pool's idle reaper onto whichever runtime polls the
request send. A connection opened by one pull leg therefore died with that
leg's runtime, and a concurrent serve that reused it lost its in-flight
request ("dispatch task is gone", #1673).

HttpOrigin worked around this with pool_max_idle_per_host(0), which paid a
fresh TCP and TLS handshake per request. S3Origin kept its shared hyper pool
with no workaround, so the race was still live for S3 origins.

Both origins now capture the runtime they are built on (IoRuntime, the
node's main runtime via build_cache) and run every request send there,
following the dial_runtime pattern from #2187. The response body stays on
the caller's runtime: hyper feeds it through a channel. HttpOrigin drops
the keep-alive workaround.

New tests in crates/cache/tests/origin_runtime_keepalive.rs cover both
backends against a raw keep-alive server. Two pull legs on throwaway
runtimes share one connection, and a leg mid-body survives the runtime
drop of the leg that opened its connection. All four fail with the spawn
bypassed: a second connection, an error, or a hang.

Closes #1675

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(cache): harden origin IoRuntime faults and cover every origin send path (#1675)

Review follow-ups for the origin IoRuntime change:

- A task the shut-down main runtime cancels is a permanent fault. A
  shut-down runtime cancels every later spawn, so retrying only waited out
  the budget and raised a false "retry budget exhausted" error.
- A panicking request task keeps its JoinError (task id and panic message)
  as the error source and logs at error level.
- HttpOrigin's headers timeout runs on the caller's runtime, so it also
  fires when the owning runtime stops polling the send.
- S3 task faults name the operation (GetObject / HeadObject).
- IoRuntime uses tokio-util's AbortOnDropHandle (workspace tokio-util
  gains the `rt` feature).
- The keep-alive tests run every sending operation (fetch, range, outboard,
  size) as the connection opener, for HTTP and S3, against a server that
  honours Range; in-flight tests cover fetch and range. Each leg has a
  deadline, and a leg that fails early surfaces its own error. Bypassing any
  one S3 send site fails its matching test.
- Docs: pull-leg runtimes drop when the leg returns; idle connections are
  reaped normally, it is the owning runtime that lives with the node;
  S3Origin::from_parts is not test-only; constructor `# Errors` sections.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(cache): document the origin runtime contract on S3Origin::new and list it as breaking (#1675)

S3Origin::new documents that its pooled connections live on the runtime it
runs on and that it fails outside a tokio runtime. The constructor changes
move from Fixed to Changed (BREAKING) in the changelog.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

decdn-node hangs in router.shutdown() on SIGTERM after any node-to-node pull; SIGKILL skips redeem and lane flush

2 participants