From: Andreas Reich Date: Wed, 8 Dec 2010 21:39:50 +0000 (-0800) Subject: Don't decrease server connection counter again if destroy() is called more than once X-Git-Tag: v0.4.3~35 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5e91042fcb70db6241a8f44bb2f6d927a8ecf125;p=platform%2Fupstream%2Fnodejs.git Don't decrease server connection counter again if destroy() is called more than once Test: Anders Conbere Fix: Andreas Reich Closes GH-431. Closes GH-502. --- diff --git a/lib/net.js b/lib/net.js index d298e9a..ab4fd25 100644 --- a/lib/net.js +++ b/lib/net.js @@ -172,7 +172,7 @@ function initSocket(self) { self._readWatcher = ioWatchers.alloc(); self._readWatcher.socket = self; self._readWatcher.callback = onReadable; - self.readable = false; + self.readable = self.destroyed = false; // Queue of buffers and string that need to be written to socket. self._writeQueue = []; @@ -788,7 +788,7 @@ Socket.prototype.destroy = function(exception) { timers.unenroll(this); - if (this.server) { + if (this.server && !this.destroyed) { this.server.connections--; } @@ -802,6 +802,8 @@ Socket.prototype.destroy = function(exception) { self.emit('close', exception ? true : false); }); } + + this.destroyed = true; }; diff --git a/test/simple/test-net-stream.js b/test/simple/test-net-stream.js new file mode 100644 index 0000000..f2dc4a8 --- /dev/null +++ b/test/simple/test-net-stream.js @@ -0,0 +1,16 @@ +var common = require('../common'); +var assert = require('assert'); + +var Stream = require('net').Stream; + +var s = new Stream(); + +// test that destroy called on a stream with a server only ever decrements the +// server connection count once + +s.server = { connections: 10 } +assert.equal(10, s.server.connections); +s.destroy() +assert.equal(9, s.server.connections); +s.destroy() +assert.equal(9, s.server.connections);