From 3527960d18b2366084ca0c7ad99c16a907e4f0fd Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 5 Mar 2016 10:22:00 -0800 Subject: [PATCH] coreplugin: tell plugins to exit cleanly before closing connections Relay tends to hang on shutdown unless it's specifically told to exit/unload first. This is probably a better solution, as it works with other plugins too. --- coreplugin.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/coreplugin.py b/coreplugin.py index 970896c..cd922d4 100644 --- a/coreplugin.py +++ b/coreplugin.py @@ -182,10 +182,22 @@ def shutdown(irc, source, args): Exits PyLink by disconnecting all networks.""" utils.checkAuthenticated(irc, source, allowOper=False) u = irc.users[source] + log.info('(%s) SHUTDOWN requested by "%s!%s@%s", exiting...', irc.name, u.nick, u.ident, u.host) + + for name, plugin in world.plugins.items(): + # Before closing connections, tell all plugins to shutdown cleanly first. + if hasattr(plugin, 'die'): + log.debug('coreplugin: Running die() on plugin %s due to shutdown.', name) + try: + plugin.die(irc) + except: # But don't allow it to crash the server. + log.exception('coreplugin: Error occurred in die() of plugin %s, skipping...', name) + for ircobj in world.networkobjects.values(): - # Disable auto-connect first by setting the time to negative. + # Disconnect all our networks. Disable auto-connect first by setting + # the time to negative. ircobj.serverdata['autoconnect'] = -1 ircobj.disconnect()