Skip to content

stream: retry read after construct when hwm is 0 - #67670

Open
hamzakargin wants to merge 1 commit into
nodejs:mainfrom
hamzakargin:stream-construct-hwm-zero
Open

hamzakargin wants to merge 1 commit into
nodejs:mainfrom
hamzakargin:stream-construct-hwm-zero

Conversation

@hamzakargin

Copy link
Copy Markdown
Contributor

A read() call made while construct() is pending is refused and leaves needReadable set. After construction, maybeReadMore() does not read for a non-flowing stream with highWaterMark: 0, so _read() was never called and toArray(), for await and 'readable' consumers waited forever.

When construction finishes and a read is pending, call read(0) on the next tick when highWaterMark is 0, the same way attaching a 'readable' listener does. Only the refused read is retried, so a highWaterMark: 0 stream that nobody reads from still does not call _read(). Streams with a higher highWaterMark still use maybeReadMore().

Fixes: #67668

Testing: the new test/parallel/test-stream-readable-construct-hwm-zero.js covers sync and async construct(), object mode, Duplex, toArray(), for await, 'readable' and 'data', and checks that _read() is not called when nothing reads. It fails without the fix and passes with it. The related fs, stream, readline, zlib and webstreams tests pass, the full parallel and sequential suites pass locally with both PRs applied, and make lint-js is clean.

AI disclosure: I used AI coding agents to help investigate the bug and write the fix and the tests. I reviewed the change, reproduced the bug on v24.22.0 and main, and checked the test results above.

A read() made while construct() is pending is refused and leaves
needReadable set. After construction, maybeReadMore() does not read
for a non-flowing stream with highWaterMark: 0, so _read() was never
called and consumers such as toArray() or for await waited forever.

Retry the refused read once construction finishes when highWaterMark
is 0.

Fixes: nodejs#67668
Assisted-by: AI coding agents
Signed-off-by: Hamza Kargın <hamzakargin@outlook.com>
@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 Node.js streams. labels Nov 21, 2026

@mcollina mcollina left a comment

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.

Lgtm

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 21, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 21, 2026
@nodejs-github-bot

This comment was marked as outdated.

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.60%. Comparing base (e8c279d) to head (708b229).
⚠️ Report is 81 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #67670   +/-   ##
=======================================
  Coverage   90.60%   90.60%           
=======================================
  Files         801      801           
  Lines      280967   281059   +92     
  Branches    54234    54252   +18     
=======================================
+ Hits       254581   254667   +86     
- Misses      16572    16583   +11     
+ Partials     9814     9809    -5     
Files with missing lines Coverage Δ
lib/internal/streams/readable.js 98.93% <100.00%> (+<0.01%) ⬆️

... and 42 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.

@christianaurichzm christianaurichzm added author ready PRs with CI started, the required approvals, and no outstanding review comments. resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. labels Nov 21, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 21, 2026
@nodejs-github-bot

This comment was marked as outdated.

@jasnell jasnell added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 22, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 22, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. needs-ci PRs that need a full CI run. stream Issues and PRs related to Node.js streams.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Readable with construct() and highWaterMark: 0 hangs in toArray() and for await

5 participants