From fe47b8b6a529233ada74dfb979e6164111737fc2 Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Fri, 6 Jul 2018 02:19:15 +0300 Subject: stream: fix readable behavior for highWaterMark === 0 Avoid trying to emit 'readable' due to the fact that state.length is always >= state.highWaterMark if highWaterMark is 0. Therefore upon .read(0) call (through .on('readable')) stream assumed that it has enough data to emit 'readable' even though state.length === 0 instead of issuing _read(). Which led to the TTY not recognizing that someone is waiting for the input. Fixes: https://github.com/nodejs/node/issues/20503 Refs: https://github.com/nodejs/node/pull/18372 PR-URL: https://github.com/nodejs/node/pull/21690 Reviewed-By: Matteo Collina Reviewed-By: Ruben Bridgewater --- test/parallel/test-readable-single-end.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/parallel/test-readable-single-end.js (limited to 'test/parallel/test-readable-single-end.js') diff --git a/test/parallel/test-readable-single-end.js b/test/parallel/test-readable-single-end.js new file mode 100644 index 0000000000..0969d49aa4 --- /dev/null +++ b/test/parallel/test-readable-single-end.js @@ -0,0 +1,16 @@ +'use strict'; + +const common = require('../common'); +const { Readable } = require('stream'); + +// This test ensures that there will not be an additional empty 'readable' +// event when stream has ended (only 1 event signalling about end) + +const r = new Readable({ + read: () => {}, +}); + +r.push(null); + +r.on('readable', common.mustCall()); +r.on('end', common.mustCall()); -- cgit v1.2.3