From ac84d44ff1b65d00efc7200a22f68e6fc78e63d7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 9 Feb 2019 17:30:33 +0100 Subject: [PATCH] worker: keep stdio after exit This addresses review comments from https://github.com/nodejs/node/pull/25871. Refs: https://github.com/nodejs/node/pull/25871 --- lib/internal/worker.js | 7 ------- test/parallel/test-worker-safe-getters.js | 14 +++++--------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/internal/worker.js b/lib/internal/worker.js index 6d833bcbd271fb..f43a9610495ac0 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -171,7 +171,6 @@ class Worker extends EventEmitter { this[kPublicPort] = null; const { stdout, stderr } = this[kParentSideStdio]; - this[kParentSideStdio] = null; if (!stdout._readableState.ended) { debug(`[${threadId}] explicitly closes stdout for ${this.threadId}`); @@ -221,20 +220,14 @@ class Worker extends EventEmitter { } get stdin() { - if (this[kParentSideStdio] === null) return null; - return this[kParentSideStdio].stdin; } get stdout() { - if (this[kParentSideStdio] === null) return null; - return this[kParentSideStdio].stdout; } get stderr() { - if (this[kParentSideStdio] === null) return null; - return this[kParentSideStdio].stderr; } } diff --git a/test/parallel/test-worker-safe-getters.js b/test/parallel/test-worker-safe-getters.js index 23c8de7c7b0cfb..69856659a5773b 100644 --- a/test/parallel/test-worker-safe-getters.js +++ b/test/parallel/test-worker-safe-getters.js @@ -12,6 +12,8 @@ if (isMainThread) { stderr: true }); + const { stdin, stdout, stderr } = w; + w.on('exit', common.mustCall((code) => { assert.strictEqual(code, 0); @@ -21,17 +23,11 @@ if (isMainThread) { w.ref(); w.unref(); - // Although not browser specific, probably wise to - // make sure the stream getters don't throw either. - w.stdin; - w.stdout; - w.stderr; - // Sanity check. assert.strictEqual(w.threadId, -1); - assert.strictEqual(w.stdin, null); - assert.strictEqual(w.stdout, null); - assert.strictEqual(w.stderr, null); + assert.strictEqual(w.stdin, stdin); + assert.strictEqual(w.stdout, stdout); + assert.strictEqual(w.stderr, stderr); })); } else { process.exit(0);