Skip to content

Commit

Permalink
test: fix test-child-process-fork-regr-gh-2847
Browse files Browse the repository at this point in the history
It's not guaranteed that the first socket that tries to connect is the
first that succeeds so the rest of assumptions made in the test are not
correct.
Fix it by making sure the second socket does not try to connect until
the first has succeeded.
The IPC channel can already be closed when sending the second socket. It
should be allowed.
Also, don't start sending messages until the worker is online.

Fixes: #8950
PR-URL: #8954
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
santigimeno committed Oct 8, 2016
1 parent 4d6297f commit 33e598a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions test/parallel/test-child-process-fork-regr-gh-2847.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,19 @@ var server = net.createServer(function(s) {
server.close();
}));

send();
send(function(err) {
// Ignore errors when sending the second handle because the worker
// may already have exited.
if (err) {
if (err.code !== 'ECONNREFUSED') {
throw err;
}
}
worker.on('online', function() {
send(function(err) {
assert.ifError(err);
send(function(err) {
// Ignore errors when sending the second handle because the worker
// may already have exited.
if (err) {
if ((err.message !== 'channel closed') &&
(err.code !== 'ECONNREFUSED')) {
throw err;
}
}
});
});
});
});

0 comments on commit 33e598a

Please sign in to comment.