Permalink
Browse files

net: fix Socket.pause null reference when called on a closed Stream

Fixes #1980.
  • Loading branch information...
1 parent e1c043f commit b3dc6f20ef0a05c2f13f049d0ac7b6e1f22f0817 @koichik committed Dec 27, 2011
Showing with 59 additions and 2 deletions.
  1. +7 −2 lib/net.js
  2. +52 −0 test/simple/test-net-after-close.js
View
9 lib/net.js
@@ -166,7 +166,10 @@ Socket.prototype.setKeepAlive = function(setting, msecs) {
Socket.prototype.address = function() {
- return this._handle.getsockname();
+ if (this._handle && this._handle.getsockname) {
+ return this._handle.getsockname();
+ }
+ return null;
};
@@ -189,7 +192,9 @@ Object.defineProperty(Socket.prototype, 'readyState', {
Object.defineProperty(Socket.prototype, 'bufferSize', {
get: function() {
- return this._handle.writeQueueSize + this._connectQueueSize;
+ if (this._handle) {
+ return this._handle.writeQueueSize + this._connectQueueSize;
+ }
}
});
View
52 test/simple/test-net-after-close.js
@@ -0,0 +1,52 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+var net = require('net');
+var closed = false;
+
+var server = net.createServer(function(s) {
+ s.end();
+});
+
+server.listen(common.PORT, function() {
+ var c = net.createConnection(common.PORT);
+ c.on('close', function() {
+ assert.strictEqual(c._handle, null);
+ closed = true;
+ assert.doesNotThrow(function() {
+ c.setNoDelay();
+ c.setKeepAlive();
+ c.bufferSize;
+ c.pause();
+ c.resume();
+ c.address();
+ c.remoteAddress;
+ c.remotePort;
+ });
+ server.close();
+ });
+});
+
+process.on('exit', function() {
+ assert(closed);
+});

0 comments on commit b3dc6f2

Please sign in to comment.