Skip to content

fix: prevent memory leak in Blob.prototype.stream() upon cancel#63772

Open
EduardF1 wants to merge 1 commit into
nodejs:mainfrom
EduardF1:fix/blob-stream-memory-leak
Open

fix: prevent memory leak in Blob.prototype.stream() upon cancel#63772
EduardF1 wants to merge 1 commit into
nodejs:mainfrom
EduardF1:fix/blob-stream-memory-leak

Conversation

@EduardF1
Copy link
Copy Markdown

@EduardF1 EduardF1 commented Jun 7, 2026

Description

Fixes #63574

Currently, calling .cancel() on a Blob stream correctly rejects pending JS pulls but leaves the internal C++ reader wakeup callback pinned in memory. This creates a detached eternal handle spanning across the C++ and JS boundary, retaining the source ArrayBuffer perpetually.

This patch surgicaly modifies the cancel lifecycle to explicitly invoke reader.setWakeup(undefined). This severs the cyclic GC reference chain between the native Node / DataQueue and the JavaScript engine, allowing V8 to correctly garbage collect the 1MiB source buffers when the stream is aborted.

Testing

Verified against the user's reproduction snippet running with --expose-gc. After 200 stream cancellations, the RSS/arrayBuffer allocation correctly dropped from ~201.0 MiB back down to 1.0 MiB baseline.

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Jun 7, 2026
@Renegade334
Copy link
Copy Markdown
Member

Renegade334 commented Jun 7, 2026

As a rule of thumb, please do not open PRs against issues with an existing active PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blob.prototype.stream() leaks the source buffer on v26

3 participants