diff --git a/lib/net.js b/lib/net.js index ab4fd2518a..6aa1453d65 100644 --- a/lib/net.js +++ b/lib/net.js @@ -877,7 +877,7 @@ function Server(/* [ options, ] listener */) { self.watcher.stop(); } - while (self.fd) { + while (typeof self.fd === 'number') { try { var peerInfo = accept(self.fd); } catch (e) { @@ -1098,7 +1098,7 @@ Server.prototype.address = function() { Server.prototype.close = function() { var self = this; - if (!self.fd) throw new Error('Not running'); + if (typeof self.fd !== 'number') throw new Error('Not running'); self.watcher.stop(); diff --git a/test/simple/test-net-server-on-fd-0.js b/test/simple/test-net-server-on-fd-0.js new file mode 100644 index 0000000000..e4390bb753 --- /dev/null +++ b/test/simple/test-net-server-on-fd-0.js @@ -0,0 +1,27 @@ +var common = require('../common'); +var assert = require('assert'); +var net = require('net'); + +process.stdin.destroy(); + +var accepted = null; +var server = net.createServer(function(socket) { + console.log('accepted'); + accepted = socket; + socket.end(); + server.close(); +}); + + +server.listen(common.PORT, function() { + console.log('listening...'); + assert.equal(server.fd, 0); + + net.createConnection(common.PORT); +}); + + +process.on('exit', function() { + assert.ok(accepted); +}); +