Skip to content

Commit d2beb1c

Browse files
committed
lib: fix worker threads can't read stdout
Fix: nodejs#24636
1 parent e958ee7 commit d2beb1c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/internal/worker.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,22 @@ class Worker extends EventEmitter {
343343
case messageTypes.STDIO_PAYLOAD:
344344
{
345345
const { stream, chunk, encoding } = message;
346-
return this[kParentSideStdio][stream].push(chunk, encoding);
346+
if (this[kParentSideStdio]) {
347+
this[kParentSideStdio][stream].push(chunk, encoding);
348+
} else {
349+
debug(`[${threadId}] explicitly closes stdout for ${this.threadId}`);
350+
}
351+
return;
347352
}
348353
case messageTypes.STDIO_WANTS_MORE_DATA:
349354
{
350355
const { stream } = message;
351-
return this[kParentSideStdio][stream][kStdioWantsMoreDataCallback]();
356+
if (this[kParentSideStdio]) {
357+
this[kParentSideStdio][stream][kStdioWantsMoreDataCallback]();
358+
} else {
359+
debug(`[${threadId}] explicitly closes stdout for ${this.threadId}`);
360+
}
361+
return;
352362
}
353363
}
354364

0 commit comments

Comments
 (0)