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 13, 2019
1 parent 03ffcf7 commit 23868ba
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 Original file line Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class Worker extends EventEmitter {
this[kPublicPort] = null; this[kPublicPort] = null;


const { stdout, stderr } = this[kParentSideStdio]; const { stdout, stderr } = this[kParentSideStdio];
this[kParentSideStdio] = null;


if (!stdout._readableState.ended) { if (!stdout._readableState.ended) {
debug(`[${threadId}] explicitly closes stdout for ${this.threadId}`); debug(`[${threadId}] explicitly closes stdout for ${this.threadId}`);
Expand Down Expand Up @@ -221,20 +220,14 @@ class Worker extends EventEmitter {
} }


get stdin() { get stdin() {
if (this[kParentSideStdio] === null) return null;

return this[kParentSideStdio].stdin; return this[kParentSideStdio].stdin;
} }


get stdout() { get stdout() {
if (this[kParentSideStdio] === null) return null;

return this[kParentSideStdio].stdout; return this[kParentSideStdio].stdout;
} }


get stderr() { get stderr() {
if (this[kParentSideStdio] === null) return null;

return this[kParentSideStdio].stderr; return this[kParentSideStdio].stderr;
} }
} }
Expand Down
14 changes: 5 additions & 9 deletions test/parallel/test-worker-safe-getters.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ if (isMainThread) {
stderr: true stderr: true
}); });


const { stdin, stdout, stderr } = w;

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


Expand All @@ -21,17 +23,11 @@ if (isMainThread) {
w.ref(); w.ref();
w.unref(); 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. // Sanity check.
assert.strictEqual(w.threadId, -1); assert.strictEqual(w.threadId, -1);
assert.strictEqual(w.stdin, null); assert.strictEqual(w.stdin, stdin);
assert.strictEqual(w.stdout, null); assert.strictEqual(w.stdout, stdout);
assert.strictEqual(w.stderr, null); assert.strictEqual(w.stderr, stderr);
})); }));
} else { } else {
process.exit(0); process.exit(0);
Expand Down

0 comments on commit 23868ba

Please sign in to comment.