Skip to content

Commit

Permalink
Merge pull request #452 from martynsmith/jirwin/fix-ping-timeouts
Browse files Browse the repository at this point in the history
fix(ping timeouts): When a ping timeout is detected properly destroy …
  • Loading branch information
jirwin committed Mar 24, 2016
2 parents 43ed448 + b47c7db commit a2233db
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ Client.prototype.connectionTimedOut = function(conn) {
// that is most current.
return;
}
self.conn.emit('close');
self.end();
};

(function() {
Expand Down Expand Up @@ -858,16 +858,7 @@ Client.prototype.connect = function(retryCount, callback) {
if (self.opt.debug)
util.log('Connection got "close" event');

// If we are abandoning a connection early (perhaps via ping timeout or
// requested disconnect), and there is still data sent over the connection
// after 'close' fires, we don't want that data leaking into the client.
// Instead, it should be ignored, so remove the data listener.
self.conn.removeListener('data', handleData);

// Stop the CyclingPingTimer for debug sanity.
self.conn.cyclingPingTimer.stop();

if (self.conn.requestedDisconnect)
if (self.conn && self.conn.requestedDisconnect)
return;
if (self.opt.debug)
util.log('Disconnected: reconnecting');
Expand All @@ -893,6 +884,15 @@ Client.prototype.connect = function(retryCount, callback) {
}
});
};

Client.prototype.end = function() {
if (this.conn) {
this.conn.cyclingPingTimer.stop();
this.conn.destroy();
}
this.conn = null;
};

Client.prototype.disconnect = function(message, callback) {
if (typeof (message) === 'function') {
callback = message;
Expand Down

0 comments on commit a2233db

Please sign in to comment.