summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-06-10 16:48:15 +0200
committerMichaël Zasso <targos@protonmail.com>2019-07-02 09:07:43 +0200
commit2053dd0c9c12242dc8d3de0e0b763f15bfb1ff0d (patch)
tree109ce4d25031bd676fee5ad4a5a39a90d2839867 /lib
parentc14e4d5bd56de06f6fb521dd22260a95ad092fec (diff)
downloadandroid-node-v8-2053dd0c9c12242dc8d3de0e0b763f15bfb1ff0d.tar.gz
android-node-v8-2053dd0c9c12242dc8d3de0e0b763f15bfb1ff0d.tar.bz2
android-node-v8-2053dd0c9c12242dc8d3de0e0b763f15bfb1ff0d.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')
-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();
+ }
});
}