Skip to content

stream: settle pending stream iter reads on return#63521

Open
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:stream-iter-pending-next-hang
Open

stream: settle pending stream iter reads on return#63521
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:stream-iter-pending-next-hang

Conversation

@trivikr
Copy link
Copy Markdown
Member

@trivikr trivikr commented May 23, 2026

This updates stream/iter cleanup so pending next() calls are settled when
a consumer calls return().

Previously, push() and broadcast() could leave a pending next() promise
unresolved if return() was called before any chunk was written. The cleanup
paths now resolve those pending reads with { done: true, value: undefined }.

Regression coverage was added for both push() and broadcast().

Fixes: #63519


Assisted-by: openai:gpt-5.5

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
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/streams

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem. labels May 23, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.13%. Comparing base (dfe2d47) to head (9651061).
⚠️ Report is 4 commits behind head on main.

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     
Files with missing lines Coverage Δ
lib/internal/streams/iter/broadcast.js 85.25% <100.00%> (+0.01%) ⬆️
lib/internal/streams/iter/push.js 92.28% <100.00%> (+0.08%) ⬆️

... and 26 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. label May 23, 2026
#resolvePendingReadsDone() {
while (this.#pendingReads.length > 0) {
this.#pendingReads.shift().resolve(
{ __proto__: null, value: undefined, done: true });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{ __proto__: null, value: undefined, done: true });
{ __proto__: null, done: true, value: undefined });

Super minor nit... just keeping the shape the same.

Copy link
Copy Markdown
Member Author

@trivikr trivikr May 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

@trivikr trivikr May 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a specific preference for the order?

In lib/**/*.js source files, excluding tests, docs, and deps:

  • done before value: 30
  • value before done: 20

In Iteration protocols for MDN, done appears before value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I submitted a PR to enforce done before value in iterator result object in #63526

@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 23, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@trivikr trivikr added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stream/iter: pending next() hangs after iterator return()

3 participants