From 5d400cfd3a2a9faf27a88bf82f33a57f78fa65af Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Wed, 6 Oct 2010 19:18:08 +0200 Subject: [PATCH] net listen should emit eaddrinuse error --- lib/net.js | 11 +++++++---- test/simple/test-net-eaddrinuse.js | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 test/simple/test-net-eaddrinuse.js diff --git a/lib/net.js b/lib/net.js index 38ee1128e5..3f75d16b47 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1189,10 +1189,13 @@ Server.prototype._startWatcher = function () { }; Server.prototype._doListen = function () { - listen(this.fd, this._backlog || 128); - this._startWatcher(); -}; - + try { + listen(this.fd, this._backlog || 128); + this._startWatcher(); + } catch (err) { + this.emit('error', err); + } +} Server.prototype.address = function () { diff --git a/test/simple/test-net-eaddrinuse.js b/test/simple/test-net-eaddrinuse.js new file mode 100644 index 0000000000..7a46f6292c --- /dev/null +++ b/test/simple/test-net-eaddrinuse.js @@ -0,0 +1,14 @@ +common = require('../common'); +assert = common.assert +net = require('net'); + +var server1 = net.createServer(function (socket) { +}); +var server2 = net.createServer(function (socket) { +}); +server1.listen(31337); +server2.addListener('error', function(error) { + assert.equal(true, error.message.indexOf('EADDRINUSE') >= 0); + server1.close(); +}); +server2.listen(31337);