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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
b016d5dffc
commit
0c6f345cda
@ -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,
|
||||
}
|
||||
@ -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.
|
||||
|
@ -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,
|
||||
}));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user