Skip to content

Commit

Permalink
test: fix cluster-worker-wait-server-close races
Browse files Browse the repository at this point in the history
Wait for data to arrive from worker before doing a disconnect. Without
this, whether the disconnect arrives at the worker before the master
accepts and forwards the connection descriptor to the worker is a race.

Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Johan Bergström <[email protected]>
Reviewed-By: Rod Vagg <[email protected]>
PR-URL: #1953
Fixes: #1933
Fixes: #1400
  • Loading branch information
sam-github committed Jun 12, 2015
1 parent 2a7fd0a commit 03ce84d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions test/parallel/test-cluster-worker-wait-server-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ var net = require('net');
if (cluster.isWorker) {
net.createServer(function(socket) {
// Wait for any data, then close connection
socket.on('data', socket.end.bind(socket));
socket.write('.');
socket.on('data', function discard() {
});
}).listen(common.PORT, common.localhostIPv4);
} else if (cluster.isMaster) {

Expand All @@ -22,11 +24,15 @@ if (cluster.isWorker) {
worker.once('listening', function() {
net.createConnection(common.PORT, common.localhostIPv4, function() {
var socket = this;
worker.disconnect();
setTimeout(function() {
socket.write('.');
connectionDone = true;
}, 1000);
this.on('data', function() {
console.log('got data from client');
// socket definitely connected to worker if we got data
worker.disconnect();
setTimeout(function() {
socket.end();
connectionDone = true;
}, 1000);
});
});
});

Expand Down

0 comments on commit 03ce84d

Please sign in to comment.