From 87b9bceacb6877e62148ea0f96f89a03f9b76a47 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 7 Feb 2018 10:52:04 +0100 Subject: [PATCH] stream: always defer readable in EOF when sync Fix a regression introduced by https://github.com/nodejs/node/pull/18515 that broke the dicer module tests. See: https://github.com/nodejs/node/pull/18515 PR-URL: https://github.com/nodejs/node/pull/18615 Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig Reviewed-By: Benjamin Gruenbaum --- lib/_stream_readable.js | 6 +++--- .../test-stream-readable-object-multi-push-async.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index c7b356ed442..46afe5f33de 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -488,9 +488,9 @@ function onEofChunk(stream, state) { } state.ended = true; - if (state.sync && state.length) { - // if we are sync and have data in the buffer, wait until next tick - // to emit the data. otherwise we risk emitting data in the flow() + if (state.sync) { + // if we are sync, wait until next tick to emit the data. + // Otherwise we risk emitting data in the flow() // the readable code triggers during a read() call emitReadable(stream); } else { diff --git a/test/parallel/test-stream-readable-object-multi-push-async.js b/test/parallel/test-stream-readable-object-multi-push-async.js index 4babfd12a27..17c84c7310e 100644 --- a/test/parallel/test-stream-readable-object-multi-push-async.js +++ b/test/parallel/test-stream-readable-object-multi-push-async.js @@ -160,7 +160,7 @@ const BATCH = 10; }); readable.on('end', common.mustCall(() => { - assert.strictEqual(nextTickPassed, false); + assert.strictEqual(nextTickPassed, true); })); }