Commit ec72574
committed
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>1 parent 73c592b commit ec72574
2 files changed
Lines changed: 73 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
453 | 453 | | |
454 | 454 | | |
455 | 455 | | |
456 | | - | |
| 456 | + | |
457 | 457 | | |
458 | | - | |
| 458 | + | |
459 | 459 | | |
460 | 460 | | |
461 | 461 | | |
462 | | - | |
| 462 | + | |
463 | 463 | | |
464 | 464 | | |
465 | 465 | | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
466 | 469 | | |
467 | 470 | | |
468 | 471 | | |
469 | 472 | | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
470 | 478 | | |
471 | 479 | | |
472 | 480 | | |
473 | 481 | | |
474 | 482 | | |
475 | 483 | | |
| 484 | + | |
476 | 485 | | |
477 | 486 | | |
478 | 487 | | |
479 | 488 | | |
| 489 | + | |
480 | 490 | | |
481 | 491 | | |
482 | 492 | | |
| |||
488 | 498 | | |
489 | 499 | | |
490 | 500 | | |
| 501 | + | |
491 | 502 | | |
492 | 503 | | |
493 | 504 | | |
| |||
497 | 508 | | |
498 | 509 | | |
499 | 510 | | |
500 | | - | |
| 511 | + | |
501 | 512 | | |
502 | 513 | | |
503 | 514 | | |
| |||
517 | 528 | | |
518 | 529 | | |
519 | 530 | | |
| 531 | + | |
520 | 532 | | |
521 | 533 | | |
522 | 534 | | |
| |||
525 | 537 | | |
526 | 538 | | |
527 | 539 | | |
| 540 | + | |
528 | 541 | | |
529 | 542 | | |
530 | 543 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
0 commit comments