diff options
author | Mikko Rantanen <jubjub@jubjubnest.net> | 2018-12-09 11:09:01 +0200 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-12-14 09:23:56 -0800 |
commit | 37a5e01bda104eacca78da31afb9f9ec05da180c (patch) | |
tree | ed33ad724a1033a516c0773a877432195869b127 /test/parallel/test-stream-readable-hwm-0-async.js | |
parent | adf5083647c3bbe2f0873a3bc6d5614a07468a94 (diff) | |
download | android-node-v8-37a5e01bda104eacca78da31afb9f9ec05da180c.tar.gz android-node-v8-37a5e01bda104eacca78da31afb9f9ec05da180c.tar.bz2 android-node-v8-37a5e01bda104eacca78da31afb9f9ec05da180c.zip |
lib: ensure readable stream flows to end
If a readable stream was set up with `highWaterMark 0`, the while-loop
in `maybeReadMore_` function would never execute.
The while loop now has an extra or-condition for the case where the
stream is flowing and there are no items. The or-condition is adapted
from the emit-condition of the `addChunk` function.
The `addChunk` also contains a check for `state.sync`. However that part
of the check was omitted here because the `maybeReadMore_` is executed
using `process.nextTick`. `state.sync` is set and then unset within the
`read()` function so it should never be in effect in `maybeReadMore_`.
Fixes: https://github.com/nodejs/node/issues/24915
PR-URL: https://github.com/nodejs/node/pull/24918
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel/test-stream-readable-hwm-0-async.js')
-rw-r--r-- | test/parallel/test-stream-readable-hwm-0-async.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/parallel/test-stream-readable-hwm-0-async.js b/test/parallel/test-stream-readable-hwm-0-async.js new file mode 100644 index 0000000000..866b524893 --- /dev/null +++ b/test/parallel/test-stream-readable-hwm-0-async.js @@ -0,0 +1,27 @@ +'use strict'; + +const common = require('../common'); + +// This test ensures that Readable stream will continue to call _read +// for streams with highWaterMark === 0 once the stream returns data +// by calling push() asynchronously. + +const { Readable } = require('stream'); + +let count = 5; + +const r = new Readable({ + // Called 6 times: First 5 return data, last one signals end of stream. + read: common.mustCall(() => { + process.nextTick(common.mustCall(() => { + if (count--) + r.push('a'); + else + r.push(null); + })); + }, 6), + highWaterMark: 0, +}); + +r.on('end', common.mustCall()); +r.on('data', common.mustCall(5)); |