diff --git a/doc/api/stream.md b/doc/api/stream.md index 4bdf3159dfaa80..8189f5c84d93ab 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 beaf9e9eb3d03d..6735bcb2b92531 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 0783aeb861100e..4eb4f326f2d295 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) {