-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit fixes an issue where sockets that are bound to a random port are keyed on port 0 instead of the actual port that was assigned to the socket.
- Loading branch information
Showing
7 changed files
with
168 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
require('../common'); | ||
var assert = require('assert'); | ||
var cluster = require('cluster'); | ||
var net = require('net'); | ||
|
||
function noop() {} | ||
|
||
if (cluster.isMaster) { | ||
var worker1 = cluster.fork(); | ||
var worker2 = cluster.fork(); | ||
|
||
worker1.on('message', onMessage); | ||
worker2.on('message', onMessage); | ||
function onMessage(obj) { | ||
assert.strictEqual(typeof obj, 'object'); | ||
assert.strictEqual(obj.msg, 'success'); | ||
assert.strictEqual(typeof obj.port, 'number'); | ||
assert.ok(obj.port !== 0, 'Expected non-zero port number from worker'); | ||
this.listens = (this.listens || 0) + 1; | ||
if (worker1.listens === 2 && worker2.listens === 2) { | ||
worker1.kill(); | ||
worker2.kill(); | ||
} | ||
} | ||
} else { | ||
net.createServer(noop).on('error', function(err) { | ||
// no errors expected | ||
process.send('server1:' + err.code); | ||
}).listen({ | ||
host: 'localhost', | ||
port: 0, | ||
exclusive: false | ||
}, function() { | ||
process.send({ | ||
msg: 'success', | ||
port: this.address().port, | ||
}); | ||
}) | ||
|
||
net.createServer(noop).on('error', function(err) { | ||
// no errors expected | ||
process.send('server2:' + err.code); | ||
}).listen({ | ||
host: 'localhost', | ||
port: 0, | ||
exclusive: false | ||
}, function() { | ||
process.send({ | ||
msg: 'success', | ||
port: this.address().port, | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters