Skip to content

Commit aee8510

Browse files
Jasper De Moordevongovett
authored andcommitted
Fix for ipc closed error in tests (#591)
* fix * Upgrade worker-farm and handle ERR_IPC_CHANNEL_CLOSED on the worker side
1 parent 8d7339a commit aee8510

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"tomlify-j0.4": "^3.0.0",
4646
"uglify-es": "^3.2.1",
4747
"v8-compile-cache": "^1.1.0",
48-
"worker-farm": "^1.4.1",
48+
"worker-farm": "^1.5.2",
4949
"ws": "^3.3.3"
5050
},
5151
"devDependencies": {

src/WorkerFarm.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ class WorkerFarm extends Farm {
5151
}
5252

5353
receive(data) {
54+
if (!this.children[data.child]) {
55+
// This handles premature death
56+
// normally only accurs for workers
57+
// that are still warming up when killed
58+
return;
59+
}
60+
5461
if (data.event) {
5562
this.emit(data.event, ...data.args);
5663
} else {
@@ -79,7 +86,13 @@ class WorkerFarm extends Farm {
7986
}
8087

8188
end() {
82-
super.end();
89+
// Force kill all children
90+
this.ending = true;
91+
for (let child in this.children) {
92+
this.stopChild(child);
93+
}
94+
95+
this.ending = false;
8396
shared = null;
8497
}
8598

src/worker.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@ exports.run = async function(path, pkg, options, isWarmUp, callback) {
3434
callback(returned);
3535
}
3636
};
37+
38+
process.on('unhandledRejection', function(err) {
39+
// ERR_IPC_CHANNEL_CLOSED happens when the worker is killed before it finishes processing
40+
if (err.code !== 'ERR_IPC_CHANNEL_CLOSED') {
41+
console.error('Unhandled promise rejection:', err.stack);
42+
}
43+
});

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5753,7 +5753,7 @@ wordwrap@~1.0.0:
57535753
version "1.0.0"
57545754
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
57555755

5756-
worker-farm@^1.4.1:
5756+
worker-farm@^1.5.2:
57575757
version "1.5.2"
57585758
resolved "https://registry.yarnpkg.com/worker-farm/-/worker-farm-1.5.2.tgz#32b312e5dc3d5d45d79ef44acc2587491cd729ae"
57595759
dependencies:

0 commit comments

Comments
 (0)