Fix GH-746 process.stdin.destroy() breaks http server

This commit is contained in:
koichik 2011-03-12 01:00:46 +09:00 committed by Ryan Dahl
parent 2a61e1cd49
commit 113b1e6e0c
2 changed files with 29 additions and 2 deletions

View File

@ -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();

View File

@ -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);
});