zlib: prevent oversized ArrayBuffer retention in one-shot methods - #65647
Open
Abhirup0 wants to merge 1 commit into
Open
zlib: prevent oversized ArrayBuffer retention in one-shot methods#65647Abhirup0 wants to merge 1 commit into
Abhirup0 wants to merge 1 commit into
Conversation
When one-shot convenience methods (zlib.gzip(), zlib.deflate(), zlib.brotliCompress(), zlib.zstdCompress(), etc.) complete with a single output chunk, zlibBufferOnEnd and processChunkSync returned bufs[0], which was a sub-slice of the 16 KB default _outBuffer. For small outputs, this retained the full 16,384-byte backing ArrayBuffer. Because this.close() synchronously frees the native C++ context and decrements the external memory accounter back to 0, V8 does not observe external memory pressure or significant JS heap growth. In long-running processes with comfortable heaps, dead ArrayBuffer allocations accumulated until the process ran out of memory. This change: 1. Trims single-chunk one-shot results to exact size with Buffer.from() when the chunk is smaller than its backing ArrayBuffer. 2. Releases internal references to _outBuffer, buffers, cb, and _writeState on stream completion, error, and close. Fixes: nodejs#65600
jasnell
approved these changes
Aug 29, 2026
Contributor
|
This PR fails many tests. Please make sure you have read and understood the following documents: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65647 +/- ##
==========================================
- Coverage 90.05% 90.05% -0.01%
==========================================
Files 754 754
Lines 255722 255742 +20
Branches 48314 48317 +3
==========================================
+ Hits 230281 230298 +17
- Misses 16555 16565 +10
+ Partials 8886 8879 -7
🚀 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: #65600
When one-shot convenience methods (
zlib.gzip(),zlib.deflate(),zlib.brotliCompress(),zlib.zstdCompress(), etc.) complete with a singleoutput chunk,
zlibBufferOnEndandprocessChunkSyncreturnedbufs[0],which was a sub-slice of the 16 KB default
_outBuffer. For small outputs,this retained the full 16,384-byte backing
ArrayBuffer.Because
this.close()synchronously frees the native C++ context anddecrements the external memory accounter back to 0, V8 does not observe
external memory pressure or significant JS heap growth. In long-running
processes with comfortable heaps, dead
ArrayBufferallocations accumulateduntil the process ran out of memory.
This change:
Buffer.from()whenthe chunk is smaller than its backing
ArrayBuffer._outBuffer,buffers,cb, and_writeStateon stream completion, error, and close.