GeezerVison is showing github.com — quic: fix wake up blob · nodejs/node@009e376
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/blob.js +15-4Lines changed: 15 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -469,9 +469,13 @@ function createBlobReaderStream(reader) { |
469 | 469 | this.pendingPulls = []; |
470 | 470 | // Lazily register a wakeup callback that the C++ side can invoke |
471 | 471 | // when new data is available after a STATUS_BLOCK. |
| 472 | + let immediate; |
472 | 473 | this.wakeup = () => { |
473 | 474 | if (this.pendingPulls.length > 0) { |
474 | | - this.readNext(c); |
| 475 | + immediate ??= setImmediate(() => { |
| 476 | + immediate = undefined; |
| 477 | + this.readNext(c); |
| 478 | + }); |
475 | 479 | } |
476 | 480 | }; |
477 | 481 | }, |
@@ -571,7 +575,15 @@ const kMaxBatchChunks = 16; |
571 | 575 | async function* createBlobReaderIterable(reader, options = kEmptyObject) { |
572 | 576 | const { getReadError } = options; |
573 | 577 | let wakeup = PromiseWithResolvers(); |
574 | | - reader.setWakeup(wakeup.resolve); |
| 578 | + let immediate; |
| 579 | + let fin = false; |
| 580 | + reader.setWakeup((setfin) => { |
| 581 | + fin ||= setfin; |
| 582 | + immediate ??= setImmediate(() => { |
| 583 | + immediate = undefined; |
| 584 | + wakeup.resolve?.(); |
| 585 | + }); |
| 586 | + }); |
575 | 587 |
|
576 | 588 | try { |
577 | 589 | while (true) { |
@@ -616,9 +628,8 @@ async function* createBlobReaderIterable(reader, options = kEmptyObject) { |
616 | 628 | if (error) throw error; |
617 | 629 |
|
618 | 630 | if (blocked) { |
619 | | - const fin = await wakeup.promise; |
| 631 | + await wakeup.promise; |
620 | 632 | wakeup = PromiseWithResolvers(); |
621 | | - reader.setWakeup(wakeup.resolve); |
622 | 633 | // If the wakeup was triggered by FIN (EndReadable), the DataQueue |
623 | 634 | // is capped. Continue the loop to pull again -- the next pull will |
624 | 635 | // return EOS. Without this, a race between the data notification |
|