summaryrefslogtreecommitdiff
path: root/lib/internal/worker/io.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-06-10 16:48:15 +0200
committerRich Trott <rtrott@gmail.com>2019-06-20 11:27:27 -0600
commitd5cf51dad589dffed2f15cc3a49d19ae13968b8f (patch)
treea97d528be238ebdf82f794d070e225355dbd3cbf /lib/internal/worker/io.js
parente57bf473517f12eb169e960aa80ffd5dcd5994d5 (diff)
downloadandroid-node-v8-d5cf51dad589dffed2f15cc3a49d19ae13968b8f.tar.gz
android-node-v8-d5cf51dad589dffed2f15cc3a49d19ae13968b8f.tar.bz2
android-node-v8-d5cf51dad589dffed2f15cc3a49d19ae13968b8f.zip
worker: only unref port for stdin if we ref’ed it before
We set the `kStartedReading` flag from `_read()` for Worker stdio, and then `ref()` the port. However, the `.on('end')` handler is also attached when `._read()` is not called, e.g. when `process.stdin` inside a Worker is prematurely ended because stdin was not enabled by the parent thread. In that case, we should not call `.unref()` for stdin if we did not also call `.ref()` for it before. Fixes: https://github.com/nodejs/node/issues/28144 PR-URL: https://github.com/nodejs/node/pull/28153 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/internal/worker/io.js')
-rw-r--r--lib/internal/worker/io.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js
index 63c8a8d976..ba2150e530 100644
--- a/lib/internal/worker/io.js
+++ b/lib/internal/worker/io.js
@@ -169,8 +169,10 @@ class ReadableWorkerStdio extends Readable {
this[kIncrementsPortRef] = true;
this[kStartedReading] = false;
this.on('end', () => {
- if (this[kIncrementsPortRef] && --this[kPort][kWaitingStreams] === 0)
- this[kPort].unref();
+ if (this[kStartedReading] && this[kIncrementsPortRef]) {
+ if (--this[kPort][kWaitingStreams] === 0)
+ this[kPort].unref();
+ }
});
}