fix(fetch): dump 3xx redirect bodies without pausing so the connection is released - #5767
Open
pacocartones wants to merge 1 commit into
Open
fix(fetch): dump 3xx redirect bodies without pausing so the connection is released#5767pacocartones wants to merge 1 commit into
pacocartones wants to merge 1 commit into
Conversation
…tion When redirect mode is 'follow', the 3xx response body is discarded and never exposed to the caller, but httpNetworkFetch still buffered it into the internal Readable. A redirect body larger than the stream's highWaterMark applied backpressure that paused and pinned the connection, so the follow-up request could never acquire it and fetch hung on a connection-limited dispatcher. Mark the hop that will be followed and drain its body (ignore the bytes but keep reading, without pausing) so the connection completes and is released back to the pool, mirroring how RedirectHandler ignores 3xx bodies on the request() path. Fixes: nodejs#5728
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5767 +/- ##
=======================================
Coverage 93.50% 93.50%
=======================================
Files 110 110
Lines 39072 39084 +12
=======================================
+ Hits 36534 36547 +13
+ Misses 2538 2537 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #5728.
Problem
fetch({ redirect: 'follow' })hangs when a 3xx redirect body is large, on a connection-limitedAgent. InhttpNetworkFetch(lib/web/fetch/index.js),onResponseDatapushed each chunk into the internalReadableand calledcontroller.pause()on backpressure. A redirect body larger than the highWaterMark (the repro uses 128 KiB) fills the buffer, pauses the socket, and — since the follow path discards the response and recurses intomainFetch— the body is never consumed. The connection staysrunning; withAgent({ connections: 1 })the follow-up can never acquire the pinned socket → hang.The
request()path (lib/handler/redirect-handler.js) already discards 3xx bodies without pausing, so it never pins the connection; the fetch path lacked the equivalent.Fix
Set
this.willFollowinonResponseStart, and inonResponseDatareturn early whenfetchParams.controller.dump || this.willFollow— discarding the bytes but not pausing, so the socket drains,onResponseEndfires, and the connection is released. Per-hop (the handler is per-dispatch), and correct because a followed 3xx body is never exposed to the caller.Test
test/issue-5728.js: RED timed out at 15s (hang); GREEN passes in ~31ms. Full redirect regression suite green (redirect-request83,redirect-stream23,fetch/redirect,client-fetch33, …),npm run lint— all green.