Skip to content

Commit

Permalink
worker: keep stdio after exit
Browse files Browse the repository at this point in the history
This addresses review comments from
#25871.

Refs: #25871

PR-URL: #26017
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
addaleax committed Feb 12, 2019
1 parent 2c84f6e commit 9e84a26
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
7 changes: 0 additions & 7 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -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;
}
}
Expand Down
14 changes: 5 additions & 9 deletions test/parallel/test-worker-safe-getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ if (isMainThread) {
stderr: true
});

const { stdin, stdout, stderr } = w;

w.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);

Expand All @@ -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);
Expand Down

0 comments on commit 9e84a26

Please sign in to comment.