Repository navigation
fs: read data when highWaterMark is 0 - #67669
Open
hamzakargin wants to merge 1 commit into
Open
hamzakargin wants to merge 1 commit into
hamzakargin wants to merge 1 commit into
Conversation
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>
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ReadStream.prototype._read()ended the stream when it was asked for 0 bytes, so anfs.ReadStreamwithhighWaterMark: 0emitted'end'without any data. Since #66956 this also hits everyfs.ReadStreamafterstream.setDefaultHighWaterMark(false, 0).When the requested size is 0, read 64 KiB, the
fs.ReadStreamdefault, instead. The size passed to_read()is only advisory, andgetDefaultHighWaterMark()can't be used here because it also returns 0 aftersetDefaultHighWaterMark(false, 0). Thestart/endlimits still apply.This fixes flowing mode (
'data',pipe()). Consuming such a stream withtoArray()orfor awaitalso needs the fix for #67668, becausefs.ReadStreamusesconstruct().Fixes: #67667
Refs: #66956
Testing: the new
test/parallel/test-fs-read-stream-hwm-zero.jsfails without the fix and passes with it. The related fs, stream, readline, zlib and webstreams tests pass, the fullparallelandsequentialsuites pass locally with both PRs applied, andmake lint-jsis 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.