Skip to content
Permalink
Browse files

worker: keep stdio after exit

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 9, 2019
1 parent 03ffcf7 commit 23868ba45eb75410cf226a99181f1d9246c6f6bb
Showing with 5 additions and 16 deletions.
  1. +0 −7 lib/internal/worker.js
  2. +5 −9 test/parallel/test-worker-safe-getters.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;
}
}
@@ -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);

0 comments on commit 23868ba

Please sign in to comment.
You can’t perform that action at this time.