Repository navigation
fetch, S3: collect an abandoned body stream whose body stalls under the high-water mark #43743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Jarred-Sumner
merged 3 commits into
main
from
robobun/1f1b7042/fetch-collect-idle-body-stream
Sep 22, 2026
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 (optional) High-throughput fetch clients that touch res.body and then drop the Response now lose a keep-alive connection per request whenever a GC lands before the short body finishes. The unroot at ByteStream.rs:119 makes the wrapper collectable as soon as JS drops it; the sweep then reaches on_body_stream_collected (FetchTasklet.rs:1767) and abort_transport closes the HTTP/1.1 socket the pool would have reused after draining. On the base the wrapper stayed rooted under the mark, the body drained, and the connection returned to the pool. Fix: for a collected stream whose remaining body is small (under the high-water mark and content-length known), drain to the mark and return the connection to the pool instead of aborting, as undici does; abort only when the remaining body exceeds the drain budget.
Why this was flagged
Trigger: any code that reads res.body (e.g. checks
res.body !== null, calls getReader() and releases it, or passes the body to a helper that never reads it) and then drops every reference before the body completes. Common in status probes, HEAD-like GETs, and libraries that access .body eagerly. Rate: once per such fetch; a GC during a body still arriving over several packets is routine under load. Mechanism: hold() at ByteStream.rs:101 now calls sync_wrapper_root, which takes the unroot branch at ByteStream.rs:119 because no sink or buffer_action exists; ReadableStream.rs:1197-1202 downgrades this_jsvalue to Weak. On sweep NewSource finalize runs consumer_collected (streams.rs:1117) -> on_body_stream_collected (FetchTasklet.rs:1767) -> abandon_response_body (FetchTasklet.rs:1931), which calls abort_transport, closing the socket. On the base branch the wrapper stayed Strong (increment_count at ReadableStream.rs:1169-1171) until buffered_len reached BODY_HIGH_WATER_MARK, so a short body completed and the keep-alive connection was reused. The PR calls this an accepted downside, but at…Verification: nit — acknowledged in diff: the PR description's "Downsides" paragraph states exactly this ("A touched stream dropped while a short body still arrives is aborted if a collection lands first. On HTTP/1.1 that closes a connection the pool would have reused"), and the bound is accurate. Trigger: JS accesses
res.body(or getReader() without reading/cancelling), drops every reference, and a GC…