From 113b1e6e0cbd6f2bd6e0d4f15addf20e0c01659f Mon Sep 17 00:00:00 2001 From: koichik Date: Sat, 12 Mar 2011 01:00:46 +0900 Subject: [PATCH] Fix GH-746 process.stdin.destroy() breaks http server --- lib/net.js | 4 ++-- test/simple/test-net-server-on-fd-0.js | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test/simple/test-net-server-on-fd-0.js diff --git a/lib/net.js b/lib/net.js index ab4fd25..6aa1453 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 0000000..e4390bb --- /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); +}); + -- 2.7.4