From 3ebce6757706baac399064443e66b17bf175f2ff Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 10 Aug 2014 21:27:50 +0100 Subject: [PATCH] Auto IRCd reconnect config option --- config.example.js | 7 +++++ server/irc/connection.js | 58 +++++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/config.example.js b/config.example.js index 17ce271..d1f21e7 100644 --- a/config.example.js +++ b/config.example.js @@ -84,6 +84,13 @@ conf.default_encoding = 'utf8'; //conf.default_gecos = 'Web IRC Client'; +/* +* Auto reconnect if the IRC server disconnects a kiwi user +* Hundreds of connected users getting disconnected then reconnecting at once may see +* high CPU usage causing further dropouts. Set to false if under high usage. +*/ +conf.ircd_reconnect = true; + /* * Client side plugins diff --git a/server/irc/connection.js b/server/irc/connection.js index 63c33a5..da5f173 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -312,37 +312,39 @@ IrcConnection.prototype.connect = function () { delete global.clients.port_pairs[that.identd_port_pair]; } - // If trying to reconnect, continue with it - if (that.reconnect_attempts && that.reconnect_attempts < 3) { - should_reconnect = true; - - // If this was an unplanned disconnect and we were originally connected OK, reconnect - } else if (!that.requested_disconnect && was_connected && safely_registered) { - should_reconnect = true; - - } else { - should_reconnect = false; - } - - if (should_reconnect) { - Stats.incr('irc.connection.reconnect'); - that.reconnect_attempts++; - that.emit('reconnecting'); - } else { - Stats.incr('irc.connection.closed'); - that.emit('close', had_error); - that.reconnect_attempts = 0; - } - // Close the whole socket down that.disposeSocket(); - // If this socket closing was not expected and we did actually connect and - // we did previously completely register on the network, then reconnect - if (should_reconnect) { - setTimeout(function() { - that.connect(); - }, 4000); + if (global.config.ircd_reconnect) { + // If trying to reconnect, continue with it + if (that.reconnect_attempts && that.reconnect_attempts < 3) { + should_reconnect = true; + + // If this was an unplanned disconnect and we were originally connected OK, reconnect + } else if (!that.requested_disconnect && was_connected && safely_registered) { + should_reconnect = true; + + } else { + should_reconnect = false; + } + + if (should_reconnect) { + Stats.incr('irc.connection.reconnect'); + that.reconnect_attempts++; + that.emit('reconnecting'); + } else { + Stats.incr('irc.connection.closed'); + that.emit('close', had_error); + that.reconnect_attempts = 0; + } + + // If this socket closing was not expected and we did actually connect and + // we did previously completely register on the network, then reconnect + if (should_reconnect) { + setTimeout(function() { + that.connect(); + }, 4000); + } } }); }); -- 2.25.1