Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: fix highwatermark threshold and add the missing error #38700

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const {
codes: {
ERR_INVALID_ARG_TYPE,
ERR_METHOD_NOT_IMPLEMENTED,
ERR_OUT_OF_RANGE,
ERR_STREAM_PUSH_AFTER_EOF,
ERR_STREAM_UNSHIFT_AFTER_END_EVENT,
}
Expand Down Expand Up @@ -363,9 +364,8 @@ Readable.prototype.setEncoding = function(enc) {
// Don't raise the hwm > 1GB.
const MAX_HWM = 0x40000000;
function computeNewHighWaterMark(n) {
if (n >= MAX_HWM) {
// TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
n = MAX_HWM;
if (n > MAX_HWM) {
throw new ERR_OUT_OF_RANGE('size', '<= 1GiB', n);
} else {
// Get the next highest power of 2 to prevent increasing hwm excessively in
// tiny amounts.
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-streams-highwatermark.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,18 @@ const { inspect } = require('util');
assert.strictEqual(readable._readableState.highWaterMark, Number(size));
});
}

{
// Test highwatermark limit
const hwm = 0x40000000 + 1;
const readable = stream.Readable({
read() {},
});

assert.throws(() => readable.read(hwm), common.expectsError({
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "size" is out of range.' +
' It must be <= 1GiB. Received ' +
hwm,
}));
}