Skip to content

Commit 593c2bc

Browse files
authored
Ensure maxListeners for process.stdout accounts for workers (#8689)
1 parent ed1e231 commit 593c2bc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/core/workers/src/WorkerFarm.js

+15
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ export default class WorkerFarm extends EventEmitter {
101101
this.localWorker.childInit != null ? this.localWorker.childInit() : null;
102102
this.run = this.createHandle('run');
103103

104+
// Worker thread stdout is by default piped into the process stdout, if there are enough worker
105+
// threads to exceed the default listener limit, then anything else piping into stdout will trigger
106+
// the `MaxListenersExceededWarning`, so we should ensure the max listeners is at least equal to the
107+
// number of workers + 1 for the main thread.
108+
//
109+
// Note this can't be fixed easily where other things pipe into stdout - even after starting > 10 worker
110+
// threads `process.stdout.getMaxListeners()` will still return 10, however adding another pipe into `stdout`
111+
// will give the warning with `<worker count + 1>` as the number of listeners.
112+
process.stdout.setMaxListeners(
113+
Math.max(
114+
process.stdout.getMaxListeners(),
115+
WorkerFarm.getNumWorkers() + 1,
116+
),
117+
);
118+
104119
this.startMaxWorkers();
105120
}
106121

0 commit comments

Comments
 (0)