Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2019-10-20 11:13:57 +0300
committerRich Trott <rtrott@gmail.com>2019-11-12 06:50:40 +0300
commitf8c069f5b88a25304ee2fc638c51464b4df196dd (patch)
tree66de4cb08640930e92c0538cf30a6cc5bca06b3f
parente55d65384d3feb3dd1bb7341a23766663fbcdba6 (diff)
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: https://github.com/nodejs/node/issues/29933 PR-URL: https://github.com/nodejs/node/pull/29938 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
-rw-r--r--doc/api/stream.md2
-rw-r--r--lib/_stream_readable.js5
-rw-r--r--test/parallel/test-readable-large-hwm.js27
3 files changed, 32 insertions, 2 deletions
diff --git a/doc/api/stream.md b/doc/api/stream.md
index b7f83a5e1b4..066d85adc49 100644
--- a/doc/api/stream.md
+++ b/doc/api/stream.md
@@ -1094,6 +1094,8 @@ buffer will be returned.
If the `size` argument is not specified, all of the data contained in the
internal buffer will be returned.
+The `size` argument must be less than or equal to 1 GB.
+
The `readable.read()` method should only be called on `Readable` streams
operating in paused mode. In flowing mode, `readable.read()` is called
automatically until the internal buffer is fully drained.
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 91cf2f75b07..71fd74b07be 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -375,10 +375,11 @@ Readable.prototype.setEncoding = function(enc) {
return this;
};
-// Don't raise the hwm > 8MB
-const MAX_HWM = 0x800000;
+// 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;
} else {
// Get the next highest power of 2 to prevent increasing hwm excessively in
diff --git a/test/parallel/test-readable-large-hwm.js b/test/parallel/test-readable-large-hwm.js
new file mode 100644
index 00000000000..d5bf25bc0e6
--- /dev/null
+++ b/test/parallel/test-readable-large-hwm.js
@@ -0,0 +1,27 @@
+'use strict';
+const common = require('../common');
+const { Readable } = require('stream');
+
+// Make sure that readable completes
+// even when reading larger buffer.
+const bufferSize = 10 * 1024 * 1024;
+let n = 0;
+const r = new Readable({
+ read() {
+ // Try to fill readable buffer piece by piece.
+ r.push(Buffer.alloc(bufferSize / 10));
+
+ if (n++ > 10) {
+ r.push(null);
+ }
+ }
+});
+
+r.on('readable', () => {
+ while (true) {
+ const ret = r.read(bufferSize);
+ if (ret === null)
+ break;
+ }
+});
+r.on('end', common.mustCall());