Repository navigation
fix(fetch): apply backpressure to deflate response decoding - #6276
Open
MIbtehajNasar wants to merge 1 commit into
Open
MIbtehajNasar wants to merge 1 commit into
MIbtehajNasar wants to merge 1 commit into
Conversation
InflateStream forwarded its inner zlib stream with a 'data' listener and ignored push()'s return value, so an unconsumed deflate body was decompressed into memory in full, unlike gzip, br and zstd. Pause the inner stream when the readable buffer is full and resume it on _read(). Fixes: nodejs#6275
ronag
approved these changes
Nov 29, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6276 +/- ##
=======================================
Coverage 91.78% 91.79%
=======================================
Files 113 113
Lines 44920 44934 +14
=======================================
+ Hits 41232 41245 +13
- Misses 3688 3689 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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...
Fixes #6275
Rationale
deflateis the only content coding that goes through the customInflateStreaminlib/web/fetch/util.js, which picks zlib or raw inflate from the first byte. It forwarded the inner stream withinflate.on('data', this.push.bind(this)), which puts the inner stream in flowing mode and ignorespush()returningfalse, so nothing ever paused decompression. An unconsumed deflate body was inflated into memory in full, while gzip, br and zstd stop at the high-water mark.Changes
Bug Fixes
'data'listener pauses the inner inflate stream whenpush()returnsfalse, and_read()resumes it. When the inner stream's own buffer fills, its write callbacks stop firing, so backpressure reaches the response body as with the other codings.test/fetch/util.jsinflate 16 MiB of zeros (zlib and raw deflate) without reading, check that less than 1 MiB is buffered, then read the stream and check all 16 MiB come through. Both fail onmain(16 MiB buffered) and pass with this change.With the reproduction from the issue (100 MiB of zeros, body not read for 1.5 s, then read in full):
arrayBuffersgrowth while unreadmainThe full body still reads back as 104,857,600 zero bytes in every case.
Breaking Changes and Deprecations
N/A
Status