Skip to content

fs: read data when highWaterMark is 0 - #67669

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
hamzakargin:fs-hwm-zero
Nov 23, 2026
Merged

nodejs-github-bot merged 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.96%. Comparing base (e8c279d) to head (e50513f).
⚠️ Report is 84 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67669      +/-   ##
==========================================
+ Coverage   90.60%   90.96%   +0.35%     
==========================================
  Files         801      801              
  Lines      280967   285960    +4993     
  Branches    54234    58511    +4277     
==========================================
+ Hits       254581   260121    +5540     
+ Misses      16572    16135     -437     
+ Partials     9814     9704     -110     
Files with missing lines Coverage Δ
lib/internal/fs/streams.js 94.49% <100.00%> (+0.02%) ⬆️

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

This comment was marked as outdated.

@nodejs-github-bot

nodejs-github-bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

@christianaurichzm

christianaurichzm commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Reopening to rerun CI on current main, the FIPS failure was fixed in #67675. No rebase needed.

@christianaurichzm christianaurichzm added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 23, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 45d1554 into nodejs:main Nov 23, 2026
117 of 119 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 45d1554

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 23, 2026
aduh95 pushed a commit that referenced this pull request Nov 23, 2026
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 #66956 for every fs.ReadStream after
stream.setDefaultHighWaterMark(false, 0).

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

Fixes: #67667
Refs: #66956
Assisted-by: AI coding agents
Signed-off-by: Hamza Kargın <hamzakargin@outlook.com>
PR-URL: #67669
Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
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

4 participants