Skip to content

Commit f0b3f41

Browse files
santigimenoMyles Borins
authored and
Myles Borins
committed
test: fix flaky child-process-fork-regr-gh-2847
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]>
1 parent 2539ade commit f0b3f41

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

test/parallel/test-child-process-fork-regr-gh-2847.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ var server = net.createServer(function(s) {
3232
var s = net.connect(common.PORT, function() {
3333
worker.send({}, s, callback);
3434
});
35+
36+
// Errors can happen if this connection
37+
// is still happening while the server has been closed.
38+
s.on('error', function(err) {
39+
if ((err.code !== 'ECONNRESET') &&
40+
((err.code !== 'ECONNREFUSED'))) {
41+
throw err;
42+
}
43+
});
3544
}
3645

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

43-
// Send 2 handles to make `process.disconnect()` wait
44-
send();
4552
send();
53+
send(function(err) {
54+
// Ignore errors when sending the second handle because the worker
55+
// may already have exited.
56+
if (err) {
57+
if (err.code !== 'ECONNREFUSED') {
58+
throw err;
59+
}
60+
}
61+
});
4662
});

0 commit comments

Comments
 (0)