Skip to content

Commit ac939d5

Browse files
mscdexMyles Borins
authored and
Myles Borins
committed
test: improve cluster-disconnect-handles test
This commit fixes two issues in test-cluster-disconnect-handles: 1. If the master's TCP connection to the worker fails, the worker process stays alive and causes many other tests that use the same common port number to also fail (with EADDRINUSE). 2. One particular problem that can cause the master's TCP connection to fail is attempting an IPv6 connection to the worker when no IPv6 network interfaces are available. PR-URL: #4084 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 22ba1b4 commit ac939d5

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

test/parallel/test-cluster-disconnect-handles.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ cluster.schedulingPolicy = cluster.SCHED_RR;
2323
// is to make sure the connection is still sitting in the master's
2424
// pending handle queue.
2525
if (cluster.isMaster) {
26+
let isKilling = false;
2627
const handles = require('internal/cluster').handles;
2728
// FIXME(bnoordhuis) lib/cluster.js scans the execArgv arguments for
2829
// debugger flags and renumbers any port numbers it sees starting
@@ -68,11 +69,30 @@ if (cluster.isMaster) {
6869
}));
6970
}));
7071
process.on('exit', () => assert.deepStrictEqual(handles, {}));
72+
process.on('uncaughtException', function(ex) {
73+
// Make sure we clean up so as not to leave a stray worker process running
74+
// if we encounter a connection or other error
75+
if (!worker.isDead()) {
76+
if (!isKilling) {
77+
isKilling = true;
78+
worker.once('exit', function() {
79+
throw ex;
80+
});
81+
worker.process.kill();
82+
}
83+
return;
84+
}
85+
throw ex;
86+
});
7187
} else {
7288
const server = net.createServer(socket => socket.pipe(socket));
73-
server.listen(() => {
89+
const cb = () => {
7490
process.send(['listening', server.address()]);
7591
debugger;
76-
});
92+
};
93+
if (common.hasIPv6)
94+
server.listen(cb);
95+
else
96+
server.listen(0, common.localhostIPv4, cb);
7797
process.on('disconnect', process.exit);
7898
}

0 commit comments

Comments
 (0)