Skip to content

Commit edf4298

Browse files
gireeshpunathiladdaleax
authored andcommitted
test: fix worker send error
In test-child-process-fork-closed-channel-segfault.js, race condition is observed between the server getting closed and the worker sending a message. Accommodate the potential errors. Earlier, the same race was observed between the client and server and was addressed through ignoring the relevant errors through error handler. The same mechanism is re-used for worker too. The only difference is that the filter is applied at the callback instead of at the worker's error listener. Refs: #3635 (comment) Fixes: #20836 PR-URL: #20973 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]>
1 parent 471d815 commit edf4298

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

test/parallel/test-child-process-fork-closed-channel-segfault.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ const server = net
3131
.listen(0, function() {
3232
const worker = cluster.fork();
3333

34+
worker.on('error', function(err) {
35+
if (
36+
err.code !== 'ECONNRESET' &&
37+
err.code !== 'ECONNREFUSED' &&
38+
err.code !== 'EMFILE'
39+
) {
40+
throw err;
41+
}
42+
});
43+
3444
function send(callback) {
3545
const s = net.connect(server.address().port, function() {
3646
worker.send({}, s, callback);
@@ -66,7 +76,10 @@ const server = net
6676
send(function(err) {
6777
// Ignore errors when sending the second handle because the worker
6878
// may already have exited.
69-
if (err && err.code !== 'ERR_IPC_CHANNEL_CLOSED') {
79+
if (err && err.code !== 'ERR_IPC_CHANNEL_CLOSED' &&
80+
err.code !== 'ECONNRESET' &&
81+
err.code !== 'ECONNREFUSED' &&
82+
err.code !== 'EMFILE') {
7083
throw err;
7184
}
7285
});

0 commit comments

Comments
 (0)