summaryrefslogtreecommitdiff
path: root/lib/_stream_readable.js
diff options
context:
space:
mode:
authorMatteo Collina <hello@matteocollina.com>2019-03-13 22:26:18 +0100
committerMatteo Collina <hello@matteocollina.com>2019-03-16 11:58:12 +0100
commit269103a0e5e30cc217bde1660087e87dfc722b8a (patch)
tree996d8d114dd8f98980c449bb99bac6e66f812c74 /lib/_stream_readable.js
parentc5e619b8ffe9e1106a3e104cc138c8bc0324c1a7 (diff)
downloadandroid-node-v8-269103a0e5e30cc217bde1660087e87dfc722b8a.tar.gz
android-node-v8-269103a0e5e30cc217bde1660087e87dfc722b8a.tar.bz2
android-node-v8-269103a0e5e30cc217bde1660087e87dfc722b8a.zip
stream: fix regression introduced in #26059
In #26059, we introduced a bug that caused 'readable' to be nextTicked on EOF of a ReadableStream. This breaks the dicer module on CITGM. That change was partially reverted to still fix the bug in #25810 and not break dicer. See: https://github.com/nodejs/node/pull/26059 Fixes: https://github.com/nodejs/node/issues/25810 PR-URL: https://github.com/nodejs/node/pull/26643 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/_stream_readable.js')
-rw-r--r--lib/_stream_readable.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 968c7b258c..fe77c44186 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -512,12 +512,24 @@ function onEofChunk(stream, state) {
}
}
state.ended = true;
- state.needReadable = false;
- // We are not protecting if emittedReadable = true,
- // so 'readable' gets scheduled anyway.
- state.emittedReadable = true;
- process.nextTick(emitReadable_, stream);
+ 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 {
+ // Emit 'readable' now to make sure it gets picked up.
+ state.needReadable = false;
+ state.emittedReadable = true;
+ // We have to emit readable now that we are EOF. Modules
+ // in the ecosystem (e.g. dicer) rely on this event being sync.
+ if (state.ended) {
+ emitReadable_(stream);
+ } else {
+ process.nextTick(emitReadable_, stream);
+ }
+ }
}
// Don't emit readable right away in sync mode, because this can trigger