stream: settle pending stream iter reads on return#63521
Conversation
Resolve pending next() calls when stream/iter push and broadcast consumers are returned, so the promises do not remain pending after iterator cleanup. Fixes: nodejs#63519 Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #63521 +/- ##
=======================================
Coverage 90.13% 90.13%
=======================================
Files 718 718
Lines 228399 228408 +9
Branches 42931 42939 +8
=======================================
+ Hits 205860 205872 +12
+ Misses 14283 14278 -5
- Partials 8256 8258 +2
🚀 New features to boost your workflow:
|
| #resolvePendingReadsDone() { | ||
| while (this.#pendingReads.length > 0) { | ||
| this.#pendingReads.shift().resolve( | ||
| { __proto__: null, value: undefined, done: true }); |
There was a problem hiding this comment.
| { __proto__: null, value: undefined, done: true }); | |
| { __proto__: null, done: true, value: undefined }); |
Super minor nit... just keeping the shape the same.
There was a problem hiding this comment.
The value comes before done in rest of push.js.
And done comes before value in rest of broadcast.js.
I'll make the change in a separate PR after this one is merged. It can happen in parallel.
There was a problem hiding this comment.
Do you have a specific preference for the order?
In lib/**/*.js source files, excluding tests, docs, and deps:
donebeforevalue: 30valuebeforedone: 20
In Iteration protocols for MDN, done appears before value.
There was a problem hiding this comment.
I submitted a PR to enforce done before value in iterator result object in #63526
This updates
stream/itercleanup so pendingnext()calls are settled whena consumer calls
return().Previously,
push()andbroadcast()could leave a pendingnext()promiseunresolved if
return()was called before any chunk was written. The cleanuppaths now resolve those pending reads with
{ done: true, value: undefined }.Regression coverage was added for both
push()andbroadcast().Fixes: #63519
Assisted-by: openai:gpt-5.5