Skip to content

Commit

Permalink
test: fix worker send error
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
gireeshpunathil authored and addaleax committed May 31, 2018
1 parent 471d815 commit edf4298
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/parallel/test-child-process-fork-closed-channel-segfault.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ const server = net
.listen(0, function() {
const worker = cluster.fork();

worker.on('error', function(err) {
if (
err.code !== 'ECONNRESET' &&
err.code !== 'ECONNREFUSED' &&
err.code !== 'EMFILE'
) {
throw err;
}
});

function send(callback) {
const s = net.connect(server.address().port, function() {
worker.send({}, s, callback);
Expand Down Expand Up @@ -66,7 +76,10 @@ const server = net
send(function(err) {
// Ignore errors when sending the second handle because the worker
// may already have exited.
if (err && err.code !== 'ERR_IPC_CHANNEL_CLOSED') {
if (err && err.code !== 'ERR_IPC_CHANNEL_CLOSED' &&
err.code !== 'ECONNRESET' &&
err.code !== 'ECONNREFUSED' &&
err.code !== 'EMFILE') {
throw err;
}
});
Expand Down

0 comments on commit edf4298

Please sign in to comment.