Repository navigation
Conversation
A response that advertises content-encoding: gzip but delivers a body that is not valid gzip in a later packet than the headers left the body stream pending forever, because the 'terminated' listener had already been removed in onComplete. The body is deferred to a later event-loop tick with setImmediate (not a wall-clock setTimeout) so it arrives in a separate packet from the headers, deterministically and without adding a fixed delay. Refs: nodejs#5999
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v7.x #6007 +/- ##
=======================================
Coverage 93.11% 93.11%
=======================================
Files 112 112
Lines 37366 37366
=======================================
Hits 34793 34793
Misses 2573 2573 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
3 of 7 tasks
metcoder95
approved these changes
Oct 16, 2026
This branch has not been deployed
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.
This relates to...
Refs #5999
Rationale
v7.xalready includes the fix for #5999 (registering theterminatedlistener only once per fetch and no longer removing it inonComplete), but it is missing a regression test.This adds the same regression test that lands on
main(and the v6 backport): a response that advertisescontent-encoding: gzipbut delivers an invalid gzip body in a later packet than the headers must rejecttext()instead of hanging forever.Notes on the test
The body must arrive in a separate packet than the headers for the regression to manifest, so the fetch controller's
terminatedlistener is removed inonCompletebefore decompression fails.Rather than a wall-clock
setTimeout(flaky, adds a fixed delay), the body is deferred to a later event-loop tick withsetImmediate. Two ticks deterministically split the headers and body into separate packets (a single tick coalesces them and does not reproduce the bug).Verification
test/fetch/encoding.js: 7/7 pass (new test ~3ms).standardlint: clean.Status