Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure maxListeners for process.stdout accounts for workers #8689

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/core/workers/src/WorkerFarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ export default class WorkerFarm extends EventEmitter {
this.localWorker.childInit != null ? this.localWorker.childInit() : null;
this.run = this.createHandle('run');

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

this.startMaxWorkers();
}

Expand Down