mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
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>
This commit is contained in:
parent
adf5083647
commit
37a5e01bda
3 changed files with 157 additions and 4 deletions
27
test/parallel/test-stream-readable-hwm-0-async.js
Normal file
27
test/parallel/test-stream-readable-hwm-0-async.js
Normal file
|
@ -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));
|
Loading…
Add table
Add a link
Reference in a new issue