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-03 21:53:58 +0300
committerRuben Bridgewater <ruben@bridgewater.de>2019-10-09 23:02:21 +0300
commit6c75cc1b11fb38448290d16c224f738f6f84fc8d (patch)
tree57da6c9a6f301b8e88404057d2f93b66ca5fef8d
parente7f604f495568091686678c1a4a612d1e0ea7889 (diff)
stream: do not deadlock duplexpair
If nothing is buffered then _read will not be called and the callback will not be invoked, effectivly deadlocking. Fixes: https://github.com/nodejs/node/issues/29758 PR-URL: https://github.com/nodejs/node/pull/29836 Refs: https://github.com/nodejs/node/pull/29649 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
-rw-r--r--doc/api/stream.md4
-rw-r--r--lib/internal/streams/duplexpair.js8
-rw-r--r--test/common/duplexpair.js8
3 files changed, 15 insertions, 5 deletions
diff --git a/doc/api/stream.md b/doc/api/stream.md
index 4bdf3159dfa..8189f5c84d9 100644
--- a/doc/api/stream.md
+++ b/doc/api/stream.md
@@ -2059,7 +2059,9 @@ when `_read()` is called again after it has stopped should it resume pushing
additional data onto the queue.
Once the `readable._read()` method has been called, it will not be called again
-until the [`readable.push()`][stream-push] method is called.
+until more data is pushed through the [`readable.push()`][stream-push] method.
+Empty data such as empty buffers and strings will not cause `readable._read()`
+to be called.
The `size` argument is advisory. For implementations where a "read" is a
single operation that returns data can use the `size` argument to determine how
diff --git a/lib/internal/streams/duplexpair.js b/lib/internal/streams/duplexpair.js
index beaf9e9eb3d..6735bcb2b92 100644
--- a/lib/internal/streams/duplexpair.js
+++ b/lib/internal/streams/duplexpair.js
@@ -20,8 +20,12 @@ class DuplexSocket extends Duplex {
}
_write(chunk, encoding, callback) {
- this[kOtherSide][kCallback] = callback;
- this[kOtherSide].push(chunk);
+ if (chunk.length === 0) {
+ process.nextTick(callback);
+ } else {
+ this[kOtherSide].push(chunk);
+ this[kOtherSide][kCallback] = callback;
+ }
}
_final(callback) {
diff --git a/test/common/duplexpair.js b/test/common/duplexpair.js
index 0783aeb8611..4eb4f326f2d 100644
--- a/test/common/duplexpair.js
+++ b/test/common/duplexpair.js
@@ -24,8 +24,12 @@ class DuplexSocket extends Duplex {
_write(chunk, encoding, callback) {
assert.notStrictEqual(this[kOtherSide], null);
assert.strictEqual(this[kOtherSide][kCallback], null);
- this[kOtherSide][kCallback] = callback;
- this[kOtherSide].push(chunk);
+ if (chunk.length === 0) {
+ process.nextTick(callback);
+ } else {
+ this[kOtherSide].push(chunk);
+ this[kOtherSide][kCallback] = callback;
+ }
}
_final(callback) {