From f31a60bad7133f877fe50570d811b320905280ab Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Tue, 21 Apr 2009 13:17:34 +0000 Subject: [PATCH] From: Alan Webb Fixes IRC reconnect problem When a session fails to establish, the login attempt eventually times out and the login is retried. This should occur once every 25 seconds (to give the server plenty of time to respond). In fact the interval was typically only 10 seconds, this was being caused by a second reset that was being scheduled when the failed listener thread was terminated. Because the second reset occurred inside the ICC timeout, it eventually gets scheduled after only 10 seconds. In addition to this, the connector was being added to the monitoring twice. This was harmless, but entirely redundant. Both of these problems have been fixed and tested. Each connector now maintains a count of how often it has been reset. The listener thread records this value on entry and checks for a change on exit. If the counts are the same, then the listener is exiting and can potentially reschedule the connection. --- .../Avatar/Chat/IRCConnector.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs index 5123ef56a8..ca85817e17 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs @@ -96,6 +96,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat internal int depends = 0; + // This variable counts the number of resets that have been performed + // on the connector. When a listener thread terminates, it checks to + // see of the reset count has changed before it schedules another + // reset. + + internal int m_resetk = 0; + // Working threads private Thread m_listener = null; @@ -229,7 +236,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat // Add the newly created connector to the known connectors list - m_connectors.Add(this); + // m_connectors.Add(this); m_log.InfoFormat("[IRC-Connector-{0}]: Initialization complete", idn); @@ -393,6 +400,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat if (m_connected) { + m_log.InfoFormat("[IRC-Connector-{0}] Resetting connector", idn); // Mark as disconnected. This will allow the listener thread @@ -410,6 +418,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat m_connected = false; m_pending = false; + m_resetk++; } @@ -478,7 +487,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat public void ListenerRun() { + string inputLine; + int resetk = m_resetk; try { @@ -534,7 +545,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat // The connection is marked as not connected the first time // through reconnect. - if (m_enabled) Reconnect(); + if (m_enabled && (m_resetk == resetk)) + Reconnect(); } @@ -830,6 +842,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat foreach (IRCConnector connector in m_connectors) { + // m_log.InfoFormat("[IRC-Watchdog] Scanning {0}", connector); if (connector.Enabled) { if (!connector.Connected) @@ -851,7 +864,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat { if (connector.m_timeout == 0) { - m_log.ErrorFormat("[IRC-Watchdog] Login timed-out for connector {0}, reconnecting", connector.idn); + // m_log.ErrorFormat("[IRC-Watchdog] Login timed-out for connector {0}, reconnecting", connector.idn); connector.Reconnect(); } else @@ -865,10 +878,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat connector.m_writer.WriteLine(String.Format("PING :{0}", connector.m_server)); connector.m_writer.Flush(); } - catch (Exception /*e*/) + catch (Exception e) { - // m_log.ErrorFormat("[IRC-PingRun] Exception on connector {0}: {1} ", connector.idn, e.Message); - // m_log.Debug(e); + m_log.ErrorFormat("[IRC-PingRun] Exception on connector {0}: {1} ", connector.idn, e.Message); + m_log.Debug(e); connector.Reconnect(); } }