buffer: fix Blob.stream() leaking source buffer · nodejs/node@ddacb3f · GitHub
Skip to content

Commit ddacb3f

Browse files
semimikohaduh95
authored andcommitted
buffer: fix Blob.stream() leaking source buffer
Blob.prototype.stream() registered a wakeup callback on the underlying source's start() and never released it. The strong Reader::wakeup_ handle kept the reader -- and through it the blob's DataQueue and backing store -- reachable as a GC root, so the source buffer leaked on every stream() call. On Node 26+, streaming a 1 MiB blob 300 times retained ~300 MiB in process.memoryUsage().arrayBuffers while the V8 heap stayed small. Register the wakeup lazily in pull() and clear it on every terminal or idle path (EOS, error, cancel, backpressure), mirroring the cleanup already done by the async iterator path. The strong handle now only lives while a pull is in flight, so the reader and its backing store become collectable once the stream finishes, errors, is cancelled, or goes idle under backpressure. Fixes: #63574 Signed-off-by: semimikoh <ejffjeosms@gmail.com> PR-URL: #63577 Fixes: #63574 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 271c745 commit ddacb3f

2 files changed

Lines changed: 73 additions & 4 deletions

File tree

lib/internal/blob.js

Lines changed: 17 additions & 4 deletions
Lines changed: 56 additions & 0 deletions

0 commit comments

Comments
 (0)