Skip to content

Commit 9cbb5e4

Browse files
committed
quic: remove unused fin flag from blob reader wakeup
The fin argument threaded from Blob::Reader::NotifyPull to the JS blob reader iterator was dead: the only consumer, `if (fin) continue;`, was the last statement in the loop and behaved identically to falling through. End-of-stream is always discovered by the subsequent pull returning EOS, never via the wakeup label. Remove the flag from the JS iterator, NotifyPull's signature/argv, and the EndReadable call site. The `!fin` coalescing bypass collapses safely because a parked reader always has pull_pending_ == false, so the first wakeup after parking always fires. Refs: nodejs#64767 Signed-off-by: Naman Trivedi <[email protected]>
1 parent ad7a5b8 commit 9cbb5e4

4 files changed

Lines changed: 11 additions & 24 deletions

File tree

‎lib/internal/blob.js‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,7 @@ async function* createBlobReaderIterable(reader, options = kEmptyObject) {
618618
const { getReadError } = options;
619619
let wakeup = PromiseWithResolvers();
620620
let immediate;
621-
let fin = false;
622-
reader.setWakeup((setfin) => {
623-
fin ||= setfin;
621+
reader.setWakeup(() => {
624622
immediate ??= setImmediate(() => {
625623
immediate = undefined;
626624
wakeup.resolve?.();
@@ -672,12 +670,6 @@ async function* createBlobReaderIterable(reader, options = kEmptyObject) {
672670
if (blocked) {
673671
await wakeup.promise;
674672
wakeup = PromiseWithResolvers();
675-
// If the wakeup was triggered by FIN (EndReadable), the DataQueue
676-
// is capped. Continue the loop to pull again -- the next pull will
677-
// return EOS. Without this, a race between the data notification
678-
// and the FIN notification can leave the iterator waiting for a
679-
// wakeup that will never come.
680-
if (fin) continue;
681673
}
682674
}
683675
} finally {

‎src/node_blob.cc‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -420,20 +420,16 @@ void Blob::Reader::SetWakeup(const FunctionCallbackInfo<Value>& args) {
420420
reader->wakeup_.Reset(args.GetIsolate(), args[0].As<Function>());
421421
}
422422

423-
void Blob::Reader::NotifyPull(bool fin) {
423+
void Blob::Reader::NotifyPull() {
424424
if (wakeup_.IsEmpty() || !env()->can_call_into_js()) return;
425-
// FIN notifications always fire — they must not be suppressed by
426-
// pull_pending_ because there will be no further notifications to
427-
// wake the iterator. Regular data notifications respect pull_pending_
428-
// to coalesce multiple deliveries within a single packet.
429-
if (!fin && pull_pending_) return;
425+
// Coalesce notifications: if a wakeup is already pending and the reader
426+
// has not yet pulled, skip re-notifying to avoid redundant wakeups
427+
// within a single packet.
428+
if (pull_pending_) return;
430429
pull_pending_ = true;
431430
HandleScope handle_scope(env()->isolate());
432431
Local<Function> fn = wakeup_.Get(env()->isolate());
433-
// Pass fin as the first argument so the JS iterator knows EOS is
434-
// imminent and should pull again without waiting for another wakeup.
435-
Local<Value> argv[] = {v8::Boolean::New(env()->isolate(), fin)};
436-
MakeCallback(fn, 1, argv);
432+
MakeCallback(fn, 0, nullptr);
437433
}
438434

439435
BaseObjectPtr<BaseObject> Blob::BlobTransferData::Deserialize(

‎src/node_blob.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Blob : public BaseObject {
8282
BaseObjectPtr<Blob> blob);
8383
static void Pull(const v8::FunctionCallbackInfo<v8::Value>& args);
8484
static void SetWakeup(const v8::FunctionCallbackInfo<v8::Value>& args);
85-
void NotifyPull(bool fin = false);
85+
void NotifyPull();
8686

8787
explicit Reader(Environment* env,
8888
v8::Local<v8::Object> obj,

‎src/quic/streams.cc‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,10 +1614,9 @@ void Stream::EndReadable(std::optional<uint64_t> maybe_final_size) {
16141614
FlushAccumulation();
16151615
set_final_size(maybe_final_size.value_or(STAT_GET(Stats, bytes_received)));
16161616
inbound_->cap(STAT_GET(Stats, final_size));
1617-
// Notify the JS reader so it can see EOS. Pass fin=true so the
1618-
// wakeup promise resolves with a value the iterator can check to
1619-
// avoid waiting for another wakeup that will never come.
1620-
if (reader_) reader_->NotifyPull(true);
1617+
// Notify the JS reader so it can see EOS. The subsequent pull observes
1618+
// the now-capped DataQueue and returns EOS.
1619+
if (reader_) reader_->NotifyPull();
16211620
}
16221621

16231622
void Stream::Destroy(QuicError error) {

0 commit comments

Comments
 (0)