Skip to content

Commit

Permalink
test: fix flaky child-process-fork-regr-gh-2847
Browse files Browse the repository at this point in the history
The test is still failing sometimes because when trying to establish the
second connection, the server is already closed. Bring back the code
that handled this case and was removed in the last refactoring of the
test. Also ignore the errors that might happen when sending the second
handle to the worker because it may already have exited.

PR-URL: #5422
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
santigimeno authored and Myles Borins committed Mar 17, 2016
1 parent 2539ade commit f0b3f41
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions test/parallel/test-child-process-fork-regr-gh-2847.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ var server = net.createServer(function(s) {
var s = net.connect(common.PORT, function() {
worker.send({}, s, callback);
});

// Errors can happen if this connection
// is still happening while the server has been closed.
s.on('error', function(err) {
if ((err.code !== 'ECONNRESET') &&
((err.code !== 'ECONNREFUSED'))) {
throw err;
}
});
}

worker.process.once('close', common.mustCall(function() {
Expand All @@ -40,7 +49,14 @@ var server = net.createServer(function(s) {
server.close();
}));

// Send 2 handles to make `process.disconnect()` wait
send();
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;
}
}
});
});

0 comments on commit f0b3f41

Please sign in to comment.