diff --git a/lib/net.js b/lib/net.js index f59fd6642aadd2..5489b219109042 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1064,26 +1064,27 @@ function listen(self, address, port, addressType, backlog, fd) { cluster._getServer(self, address, port, addressType, fd, function(handle, err) { - // EACCESS and friends - if (err) { - self.emit('error', errnoException(err, 'bind')); - return; - } - - // Some operating systems (notably OS X and Solaris) don't report EADDRINUSE - // errors right away. libuv mimics that behavior for the sake of platform - // consistency but that means we have have a socket on our hands that is - // not actually bound. That's why we check if the actual port matches what - // we requested and if not, raise an error. The exception is when port == 0 - // because that means "any random port". - if (port && handle.getsockname && port != handle.getsockname().port) { - self.emit('error', errnoException('EADDRINUSE', 'bind')); - return; - } - - self._handle = handle; - self._listen2(address, port, addressType, backlog, fd); - }); + // EACCESS and friends + if (err) { + self.emit('error', errnoException(err, 'bind')); + return; + } + + // Some operating systems (notably OS X and Solaris) don't report + // EADDRINUSE errors right away. libuv mimics that behavior for the + // sake of platform consistency but that means we have have a socket on + // our hands that is not actually bound. That's why we check if the + // actual port matches what we requested and if not, raise an error. + // The exception is when port == 0 because that means "any random + // port". + if (port && handle.getsockname && port != handle.getsockname().port) { + self.emit('error', errnoException('EADDRINUSE', 'bind')); + return; + } + + self._handle = handle; + self._listen2(address, port, addressType, backlog, fd); + }); }