Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ping timeouts): When a ping timeout is detected properly destroy … #452

Merged
merged 1 commit into from
Mar 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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