Skip to content

fs: read data when highWaterMark is 0 - #67669

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

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

Conversation

@hamzakargin

Copy link
Copy Markdown
Contributor

ReadStream.prototype._read() ended the stream when it was asked for 0 bytes, so an fs.ReadStream with highWaterMark: 0 emitted 'end' without any data. Since #66956 this also hits every fs.ReadStream after stream.setDefaultHighWaterMark(false, 0).

When the requested size is 0, read 64 KiB, the fs.ReadStream default, instead. The size passed to _read() is only advisory, and getDefaultHighWaterMark() can't be used here because it also returns 0 after setDefaultHighWaterMark(false, 0). The start/end limits still apply.

This fixes flowing mode ('data', pipe()). Consuming such a stream with toArray() or for await also needs the fix for #67668, because fs.ReadStream uses construct().

Fixes: #67667
Refs: #66956

Testing: the new test/parallel/test-fs-read-stream-hwm-zero.js 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.

ReadStream.prototype._read() passed the requested size straight to
the end-of-range check, so a size of 0 ended the stream before any
data was read. This happened for createReadStream() with
highWaterMark: 0, and since nodejs#66956 for every fs.ReadStream after
stream.setDefaultHighWaterMark(false, 0).

Read 64 KiB, the ReadStream default, when the requested size is 0.

Fixes: nodejs#67667
Refs: nodejs#66956
Assisted-by: AI coding agents
Signed-off-by: Hamza Kargın <hamzakargin@outlook.com>
@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Nov 21, 2026
@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.61%. Comparing base (e8c279d) to head (e50513f).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #67669   +/-   ##
=======================================
  Coverage   90.60%   90.61%           
=======================================
  Files         801      801           
  Lines      280967   281059   +92     
  Branches    54234    54257   +23     
=======================================
+ Hits       254581   254675   +94     
+ Misses      16572    16568    -4     
- Partials     9814     9816    +2     
Files with missing lines Coverage Δ
lib/internal/fs/streams.js 94.49% <100.00%> (+0.02%) ⬆️

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

@christianaurichzm christianaurichzm added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels 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

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. fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs.createReadStream() with highWaterMark: 0 ends without reading any data

3 participants