Skip to content

Commit

Permalink
Fix for ipc closed error in tests (#591)
Browse files Browse the repository at this point in the history
* fix

* Upgrade worker-farm and handle ERR_IPC_CHANNEL_CLOSED on the worker side
  • Loading branch information
Jasper De Moor authored and devongovett committed Jan 26, 2018
1 parent 8d7339a commit aee8510
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
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

0 comments on commit aee8510

Please sign in to comment.