Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
net: fix Socket.pause null reference when called on a closed Stream
Browse files Browse the repository at this point in the history
Fixes #1980.
  • Loading branch information
koichik committed Dec 28, 2011
1 parent e1c043f commit a848a3e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/net.js
Expand Up @@ -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;
};


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

Expand Down
52 changes: 52 additions & 0 deletions 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 a848a3e

Please sign in to comment.