diff --git a/lib/net.js b/lib/net.js index 65a8c5e55c..b9bbad7762 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1075,7 +1075,7 @@ Server.prototype.listen = function () { self.addListener('listening', lastArg); } - var port = toPort(arguments[0]); + var port = toPort(arguments[0] != lastArg ? arguments[0] : null); if (port === false) { // the first argument specifies a path self.fd = socket('unix'); diff --git a/test/simple/test-net-server-listen-assigned-port.js b/test/simple/test-net-server-listen-assigned-port.js new file mode 100644 index 0000000000..4bfffec446 --- /dev/null +++ b/test/simple/test-net-server-listen-assigned-port.js @@ -0,0 +1,19 @@ +var common = require('../common'); +net = require('net'); +assert = require('assert'); + +var address; + +var server = net.createServer(function (socket) { +}); + +server.listen(function() { + address = server.address(); + console.log("opened server on %j", address); + server.close(); +}); + +process.on('exit', function () { + assert.ok(address.port > 100); +}); +