Repository navigation
fix(cache): run origin request sends on the node's main runtime and restore HTTP keep-alive - #2308
Merged
Merged
Conversation
…estore 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]>
…d 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]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new S3 runtime contract needs public API documentation, and its breaking signature change belongs in the breaking-changes section.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Routes HTTP and S3 request sends through the node’s main runtime, preventing pooled connections from dying with temporary pull-leg runtimes.
Changes:
- Adds
IoRuntimefor runtime-owned request tasks. - Restores HTTP keep-alive and wraps all S3 sends.
- Adds cross-runtime keep-alive and in-flight regression tests.
| File | Description |
|---|---|
Cargo.toml |
Enables Tokio task utilities. |
CHANGELOG.md |
Documents origin runtime changes. |
crates/cache/src/origin/io_runtime.rs |
Implements runtime capture and task execution. |
crates/cache/src/origin/http.rs |
Routes requests through the captured runtime. |
crates/cache/src/origin/s3.rs |
Routes SDK requests through the captured runtime. |
crates/cache/src/origin/mod.rs |
Registers the runtime module. |
crates/cache/tests/origin_runtime_keepalive.rs |
Adds keep-alive and in-flight regressions. |
crates/cache/tests/s3_origin.rs |
Adapts tests to fallible construction. |
crates/node/src/runtime/mod.rs |
Documents main-runtime origin construction. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…d 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]>
6 tasks done
Code Coverage OverviewLanguages: Rust Rust / code-coverage/cargo-llvm-covThe overall line coverage in commit 6757fd6 in the Show a line coverage summary of the most impacted files.
|
This was referenced Oct 5, 2026
Closed
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
A serve-miss pull leg runs on its own current-thread runtime, and that runtime drops when the leg returns. hyper-util's pooled client spawns three tasks onto whichever runtime polls the request send: each connection's dispatch task, the task that returns a connection to the pool, and the pool's idle reaper. So a connection opened by one pull leg died with that leg's runtime. A concurrent leg that reused the connection then lost its in-flight request with "dispatch task is gone" (#1673).
HttpOriginworked around this withpool_max_idle_per_host(0), which costs a fresh TCP and TLS handshake on every request.S3Originkept its shared hyper pool and had no workaround, so the race is still live onmainfor S3 origins.This PR applies the same approach as #2187's
dial_runtime:IoRuntime(crates/cache/src/origin/io_runtime.rs) captures the runtime an origin is built on. In the node that is the main runtime, viabuild_cache.HttpOrigindrops the keep-alive workaround.Closes #1675
Reviewer notes
crates/cache/src/origin/io_runtime.rs, thenHttpOrigin::sendinhttp.rs, then the four wrapped.send()sites ins3.rs.HttpOrigin::newandS3Origin::newcaptureHandle::try_current(). They do not take an explicit handle.build_cacheon the#[tokio::main]runtime.S3Origin::from_partsreturnsanyhow::Result<Self>.HttpOrigin's headers timeout runs on the caller's side, so it still fires if the owning runtime stops polling the send. Dropping the send aborts the spawned task (AbortOnDropHandle).main.tokio-utilgains thertfeature forAbortOnDropHandle.AbortOnDropcopies inclient,cliandnode. They could move totokio_util::task::AbortOnDropHandleas a follow-up.main, or live in a test binary that never builds an HTTP or S3 origin. Filed as flaky(test): node_origin_pull sliver-voucher test reads frames cancel-unsafely under timeout (postcard decode error) #2306 and flaky(test): origin_range_pull::throwaway_open_then_real_open_shares_one_multi_draw_fill fetches the first draw twice #2307, with more sightings added to flaky(test): node_origin_pull::node_origin_not_found_refusal_does_not_tar_upstream fails ~50% since #2248 #2268.Verification
cargo fmt -- --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo nextest rundecdn-cache: 513/513 pass.decdn-node: 1559/1559 pass.two_concurrent_disjoint_own_origin_misses_two_fetches_no_wedge(Flaky serve-miss coalescing tests under CI coverage contention (early-eof / peer hang, B3 #1656) #1673 regression test): 20/20 pass.RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-itemspre-commit run --all-filescrates/cache/tests/origin_runtime_keepalive.rs, 12 in total. They run against a raw keep-alive server that counts TCP connections and honoursRange.IoRuntime::runbypassed, every test fails (a second connection, an error, or a hang).CHANGELOG.mdentry added (Fixed)fix(cache): …🤖 Generated with Claude Code