Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0c6f345

Browse filesBrowse files
pd4d10nodejs-github-bot
authored andcommitted
stream: fix highwatermark threshold and add the missing error
1. Fix highwatermark threshold: `< 1GiB` -> `<= 1GiB` 2. Add the missing error: Size out of range Update test/parallel/test-streams-highwatermark.js Co-authored-by: Darshan Sen <raisinten@gmail.com> PR-URL: #38700 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent b016d5d commit 0c6f345
Copy full SHA for 0c6f345

File tree

Expand file treeCollapse file tree

2 files changed

+18
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-3
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/readable.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/readable.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const {
6262
codes: {
6363
ERR_INVALID_ARG_TYPE,
6464
ERR_METHOD_NOT_IMPLEMENTED,
65+
ERR_OUT_OF_RANGE,
6566
ERR_STREAM_PUSH_AFTER_EOF,
6667
ERR_STREAM_UNSHIFT_AFTER_END_EVENT,
6768
}
@@ -363,9 +364,8 @@ Readable.prototype.setEncoding = function(enc) {
363364
// Don't raise the hwm > 1GB.
364365
const MAX_HWM = 0x40000000;
365366
function computeNewHighWaterMark(n) {
366-
if (n >= MAX_HWM) {
367-
// TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
368-
n = MAX_HWM;
367+
if (n > MAX_HWM) {
368+
throw new ERR_OUT_OF_RANGE('size', '<= 1GiB', n);
369369
} else {
370370
// Get the next highest power of 2 to prevent increasing hwm excessively in
371371
// tiny amounts.
Collapse file

‎test/parallel/test-streams-highwatermark.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-streams-highwatermark.js
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,18 @@ const { inspect } = require('util');
7070
assert.strictEqual(readable._readableState.highWaterMark, Number(size));
7171
});
7272
}
73+
74+
{
75+
// Test highwatermark limit
76+
const hwm = 0x40000000 + 1;
77+
const readable = stream.Readable({
78+
read() {},
79+
});
80+
81+
assert.throws(() => readable.read(hwm), common.expectsError({
82+
code: 'ERR_OUT_OF_RANGE',
83+
message: 'The value of "size" is out of range.' +
84+
' It must be <= 1GiB. Received ' +
85+
hwm,
86+
}));
87+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.