Skip to content

Commit 23868ba

Browse files
committed
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>
1 parent 03ffcf7 commit 23868ba

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

lib/internal/worker.js

-7
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ class Worker extends EventEmitter {
171171
this[kPublicPort] = null;
172172

173173
const { stdout, stderr } = this[kParentSideStdio];
174-
this[kParentSideStdio] = null;
175174

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

223222
get stdin() {
224-
if (this[kParentSideStdio] === null) return null;
225-
226223
return this[kParentSideStdio].stdin;
227224
}
228225

229226
get stdout() {
230-
if (this[kParentSideStdio] === null) return null;
231-
232227
return this[kParentSideStdio].stdout;
233228
}
234229

235230
get stderr() {
236-
if (this[kParentSideStdio] === null) return null;
237-
238231
return this[kParentSideStdio].stderr;
239232
}
240233
}

test/parallel/test-worker-safe-getters.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ if (isMainThread) {
1212
stderr: true
1313
});
1414

15+
const { stdin, stdout, stderr } = w;
16+
1517
w.on('exit', common.mustCall((code) => {
1618
assert.strictEqual(code, 0);
1719

@@ -21,17 +23,11 @@ if (isMainThread) {
2123
w.ref();
2224
w.unref();
2325

24-
// Although not browser specific, probably wise to
25-
// make sure the stream getters don't throw either.
26-
w.stdin;
27-
w.stdout;
28-
w.stderr;
29-
3026
// Sanity check.
3127
assert.strictEqual(w.threadId, -1);
32-
assert.strictEqual(w.stdin, null);
33-
assert.strictEqual(w.stdout, null);
34-
assert.strictEqual(w.stderr, null);
28+
assert.strictEqual(w.stdin, stdin);
29+
assert.strictEqual(w.stdout, stdout);
30+
assert.strictEqual(w.stderr, stderr);
3531
}));
3632
} else {
3733
process.exit(0);

0 commit comments

Comments
 (0)