Skip to content
Merged
Show file tree
Hide file tree
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
70 changes: 38 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/WorkerPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ class PoolWorker {
this.worker = childProcess.spawn(process.execPath, [].concat(options.nodeArgs || []).concat(workerPath, options.parallelJobs), {
stdio: ['ignore', 1, 2, 'pipe', 'pipe'],
});

// This prevents a problem where the worker stdio can be undefined
// when the kernel hits the limit of open files.
// More info can be found on: https://github.com/webpack-contrib/thread-loader/issues/2
if (!this.worker.stdio) {
throw new Error(`Failed to create the worker pool with workerId: ${workerId} and ${''
}configuration: ${JSON.stringify(options)}. Please verify if you hit the OS open files limit.`);
}

const [, , , readPipe, writePipe] = this.worker.stdio;
this.readPipe = readPipe;
this.writePipe = writePipe;
Expand Down
3 changes: 3 additions & 0 deletions test/__snapshots__/workerPool.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`workerPool should throw an error when worker.stdio is undefined 1`] = `"Failed to create the worker pool with workerId: 1 and configuration: {}. Please verify if you hit the OS open files limit."`;
32 changes: 32 additions & 0 deletions test/workerPool.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import childProcess from 'child_process';
import stream from 'stream';
import WorkerPool from '../src/WorkerPool';

jest.mock('child_process', () => {
return {
spawn: jest.fn(() => {
return {};
}),
};
});

describe('workerPool', () => {
it('should throw an error when worker.stdio is undefined', () => {
childProcess.spawn.mockImplementationOnce(() => { return {}; });

const workerPool = new WorkerPool({});
expect(() => workerPool.createWorker()).toThrowErrorMatchingSnapshot();
expect(() => workerPool.createWorker()).toThrowError('Please verify if you hit the OS open files limit');
});

it('should not throw an error when worker.stdio is defined', () => {
childProcess.spawn.mockImplementationOnce(() => {
return {
stdio: new Array(5).fill(new stream.PassThrough()),
};
});

const workerPool = new WorkerPool({});
expect(() => workerPool.createWorker()).not.toThrow();
});
});