From b47c7dbbefd9e9e7997fcb4d924dc5d966d913cb Mon Sep 17 00:00:00 2001 From: Justin Gallardo Date: Thu, 10 Mar 2016 00:56:26 -0800 Subject: [PATCH] fix(ping timeouts): When a ping timeout is detected properly destroy the existing connection before making a new one. --- lib/irc.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/irc.js b/lib/irc.js index cc212f87..856c233b 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -675,7 +675,7 @@ Client.prototype.connectionTimedOut = function(conn) { // that is most current. return; } - self.conn.emit('close'); + self.end(); }; (function() { @@ -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'); @@ -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;