From 5bffe6741677a2dd0e89443488ccf9c1bdb117d5 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 11 Mar 2018 21:26:37 -0700 Subject: [PATCH] relay: bandaid patch for freezes on startup when there are a ton of networks The side effect of this patch is that it makes large bursts *really* CPU intensive. A proper fix for this will hopefully be introduced in the future. --- plugins/relay.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/relay.py b/plugins/relay.py index 1dc2ba3..b856776 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -33,10 +33,7 @@ default_permissions = {"*!*@*": ['relay.linked'], def initialize_all(irc): """Initializes all relay channels for the given IRC object.""" - # Wait for all IRC objects to be created first. This prevents - # relay servers from being spawned too early (before server authentication), - # which would break connections. - if world.started.wait(TCONDITION_TIMEOUT): + def _initialize_all(): for chanpair, entrydata in db.items(): network, channel = chanpair @@ -48,6 +45,14 @@ def initialize_all(irc): if network == irc.name: initialize_channel(irc, channel) + # Wait for all IRC objects to be created first. This prevents + # relay servers from being spawned too early (before server authentication), + # which would break connections. + if world.started.wait(TCONDITION_TIMEOUT): + t = threading.Thread(target=_initialize_all, daemon=True, + name='relay initialize_all thread from network %r' % irc.name) + t.start() + def main(irc=None): """Main function, called during plugin loading at start.""" log.debug('relay.main: loading links database') @@ -500,9 +505,8 @@ def initialize_channel(irc, channel): # from the config. Skip this. continue - # Give each network a tiny bit of leeway to finish up its connection. - # This is better than just dropping users their completely. - if not remoteirc.connected.wait(TCONDITION_TIMEOUT): + # Remote net isn't ready yet, try again later. + if not remoteirc.connected.is_set(): continue # Join their (remote) users and set their modes, if applicable.