stream: increase MAX_HWM · nodejs/node@77e0318 · GitHub
Skip to content

Commit 77e0318

Browse files
ronagBethGriggs
authored andcommitted
stream: increase MAX_HWM
MAX_HWM was added in 9208c89 where the highwatermark was changed to always increase in steps of highest power of 2 to prevent increasing hwm excessivly in tiny amounts. Why a limit was added on the highwatermark is unclear but breaks existing usage where a larger read size is used. The invariant for read(n) is that a buffer of size n is always returned. Considering a maximum ceiling on the buffer size breaks this invariant. This PR significantly increases the limit to make it less likely to break the previous invariant and also documents the limit. Fixes: #29933 PR-URL: #29938 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent a1b095d commit 77e0318

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

doc/api/stream.md

Lines changed: 2 additions & 0 deletions

lib/_stream_readable.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,11 @@ Readable.prototype.setEncoding = function(enc) {
340340
return this;
341341
};
342342

343-
// Don't raise the hwm > 8MB
344-
const MAX_HWM = 0x800000;
343+
// Don't raise the hwm > 1GB
344+
const MAX_HWM = 0x40000000;
345345
function computeNewHighWaterMark(n) {
346346
if (n >= MAX_HWM) {
347+
// TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
347348
n = MAX_HWM;
348349
} else {
349350
// Get the next highest power of 2 to prevent increasing hwm excessively in
Lines changed: 27 additions & 0 deletions

0 commit comments

Comments
 (0)