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

Fix for ipc closed error in tests #591

Merged
merged 2 commits into from
Jan 26, 2018
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"tomlify-j0.4": "^3.0.0",
"uglify-es": "^3.2.1",
"v8-compile-cache": "^1.1.0",
"worker-farm": "^1.4.1",
"worker-farm": "^1.5.2",
"ws": "^3.3.3"
},
"devDependencies": {
Expand Down
15 changes: 14 additions & 1 deletion src/WorkerFarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class WorkerFarm extends Farm {
}

receive(data) {
if (!this.children[data.child]) {
// This handles premature death
// normally only accurs for workers
// that are still warming up when killed
return;
}

if (data.event) {
this.emit(data.event, ...data.args);
} else {
Expand Down Expand Up @@ -79,7 +86,13 @@ class WorkerFarm extends Farm {
}

end() {
super.end();
// Force kill all children
this.ending = true;
for (let child in this.children) {
this.stopChild(child);
}

this.ending = false;
shared = null;
}

Expand Down
7 changes: 7 additions & 0 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ exports.run = async function(path, pkg, options, isWarmUp, callback) {
callback(returned);
}
};

process.on('unhandledRejection', function(err) {
// ERR_IPC_CHANNEL_CLOSED happens when the worker is killed before it finishes processing
if (err.code !== 'ERR_IPC_CHANNEL_CLOSED') {
console.error('Unhandled promise rejection:', err.stack);
}
});
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5753,7 +5753,7 @@ wordwrap@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"

worker-farm@^1.4.1:
worker-farm@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/worker-farm/-/worker-farm-1.5.2.tgz#32b312e5dc3d5d45d79ef44acc2587491cd729ae"
dependencies:
Expand Down