Skip to content

Commit 5e9751e

Browse files
committed
quic: Fix wake up blob
1 parent b60ce09 commit 5e9751e

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

lib/internal/blob.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,15 @@ function createBlobReaderStream(reader) {
475475
this.pendingPulls = [];
476476
// Register a wakeup callback that the C++ side can invoke
477477
// when new data is available after a STATUS_BLOCK.
478+
let immediate;
478479
reader.setWakeup(() => {
479-
if (this.pendingPulls.length > 0) {
480-
this.readNext(c);
480+
if (this.pendingPulls.length > 0 &&
481+
typeof immediate === 'undefined') {
482+
// Postpone the execution to the next steps of the event loop
483+
immediate = setImmediate(() => {
484+
immediate = undefined;
485+
this.readNext(c);
486+
});
481487
}
482488
});
483489
},
@@ -564,7 +570,16 @@ const kMaxBatchChunks = 16;
564570
async function* createBlobReaderIterable(reader, options = kEmptyObject) {
565571
const { getReadError } = options;
566572
let wakeup = PromiseWithResolvers();
567-
reader.setWakeup(wakeup.resolve);
573+
let immediate;
574+
reader.setWakeup(() => {
575+
if (typeof immediate === 'undefined') {
576+
// Postpone the execution to the next steps of the event loop
577+
immediate = setImmediate(() => {
578+
immediate = undefined;
579+
wakeup.resolve?.();
580+
});
581+
}
582+
});
568583

569584
try {
570585
while (true) {
@@ -611,7 +626,6 @@ async function* createBlobReaderIterable(reader, options = kEmptyObject) {
611626
if (blocked) {
612627
const fin = await wakeup.promise;
613628
wakeup = PromiseWithResolvers();
614-
reader.setWakeup(wakeup.resolve);
615629
// If the wakeup was triggered by FIN (EndReadable), the DataQueue
616630
// is capped. Continue the loop to pull again -- the next pull will
617631
// return EOS. Without this, a race between the data notification

0 commit comments

Comments
 (0)