From a787f79f367000240b1e66645407caae4ae33b5e Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 28 Jul 2013 21:43:46 +0100 Subject: [PATCH] Correctly disposing IrcConnection --- server/irc/connection.js | 28 ++++++++++++++-------------- server/irc/state.js | 1 - 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/server/irc/connection.js b/server/irc/connection.js index 2f07ba8..7801587 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -330,6 +330,18 @@ IrcConnection.prototype.end = function (data, callback) { IrcConnection.prototype.dispose = function () { var that = this; + // If we're still connected, wait until the socket is closed before disposing + // so that all the events are still correctly triggered + if (this.socket && this.connected) { + this.socket.end(); + return; + } + + if (this.socket) { + this.disposeSocket(); + this.removeAllListeners(); + } + _.each(this.irc_users, function (user) { user.dispose(); }); @@ -342,22 +354,10 @@ IrcConnection.prototype.dispose = function () { this.server.dispose(); this.server = undefined; - EventBinder.unbindIrcEvents('', this.irc_events, this); + this.irc_commands = undefined; - // If we're still connected, wait until the socket is closed before disposing - // so that all the events are still correctly triggered - if (this.socket && this.connected) { - this.socket.once('close', function() { - that.disposeSocket(); - that.removeAllListeners(); - }); - - this.socket.end(); + EventBinder.unbindIrcEvents('', this.irc_events, this); - } else { - this.disposeSocket(); - this.removeAllListeners(); - } }; diff --git a/server/irc/state.js b/server/irc/state.js index e63451a..67d8351 100755 --- a/server/irc/state.js +++ b/server/irc/state.js @@ -18,7 +18,6 @@ var State = function (client, save_state) { _.each(that.irc_connections, function (irc_connection, i, cons) { if (irc_connection) { irc_connection.end('QUIT :' + (global.config.quit_message || '')); - irc_connection.dispose(); global.servers.removeConnection(irc_connection); cons[i] = null; } -- 2.25.1