From d21344342d7c69a2f7ca578692d27c8907219920 Mon Sep 17 00:00:00 2001 From: James Lu Date: Wed, 30 Mar 2016 18:33:44 -0700 Subject: [PATCH 1/3] relay: experimental fix for #183 --- plugins/relay.py | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/plugins/relay.py b/plugins/relay.py index 5805f8d..aaeaed2 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -237,7 +237,6 @@ def getRemoteSid(irc, remoteirc): except ValueError: # Network not initialized yet. log.exception('(%s) Failed to spawn server for %r:', irc.name, remoteirc.name) - irc.disconnect() return else: irc.servers[sid].remote = remoteirc.name @@ -1178,36 +1177,38 @@ def handle_disconnect(irc, numeric, command, args): """Handles IRC network disconnections (internal hook).""" # Quit all of our users' representations on other nets, and remove # them from our relay clients index. - for k, v in relayusers.copy().items(): - if irc.name in v: - del relayusers[k][irc.name] - if k[0] == irc.name: - try: - handle_quit(irc, k[1], 'PYLINK_DISCONNECT', {'text': 'Relay network lost connection.'}) - del relayusers[k] - except KeyError: - pass + with spawnlocks[irc.name]: + for k, v in relayusers.copy().items(): + if irc.name in v: + del relayusers[k][irc.name] + if k[0] == irc.name: + try: + handle_quit(irc, k[1], 'PYLINK_DISCONNECT', {'text': 'Relay network lost connection.'}) + del relayusers[k] + except KeyError: + pass # SQUIT all relay pseudoservers spawned for us, and remove them # from our relay subservers index. - for name, ircobj in world.networkobjects.copy().items(): - if name != irc.name and ircobj.connected.is_set(): + with spawnlocks_servers[irc.name]: + for name, ircobj in world.networkobjects.copy().items(): + if name != irc.name and ircobj.connected.is_set(): + try: + rsid = relayservers[name][irc.name] + except KeyError: + continue + else: + ircobj.proto.squit(ircobj.sid, rsid, text='Relay network lost connection.') + try: - rsid = relayservers[name][irc.name] + del relayservers[name][irc.name] except KeyError: - continue - else: - ircobj.proto.squit(ircobj.sid, rsid, text='Relay network lost connection.') + pass try: - del relayservers[name][irc.name] + del relayservers[irc.name] except KeyError: pass - try: - del relayservers[irc.name] - except KeyError: - pass - utils.add_hook(handle_disconnect, "PYLINK_DISCONNECT") def handle_save(irc, numeric, command, args): From 9e33081bc9544d59316833c7d1a75fce517c087e Mon Sep 17 00:00:00 2001 From: James Lu Date: Wed, 30 Mar 2016 21:22:18 -0700 Subject: [PATCH 2/3] relay: fix typo in comment --- plugins/relay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/relay.py b/plugins/relay.py index 5805f8d..9757952 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -175,7 +175,7 @@ def scheduleExport(starting=False): global exportdb_timer if not starting: - # Export the datbase, unless this is being called the first + # Export the database, unless this is being called the first # thing after start (i.e. DB has just been loaded). exportDB() From 3a8b0aa123c32c55ea4cb599fe56c613c74c2d64 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 1 Apr 2016 18:31:53 -0700 Subject: [PATCH 3/3] relay: catch OSError too when loading DB --- plugins/relay.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/relay.py b/plugins/relay.py index aaeaed2..a2bf4c3 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -156,9 +156,9 @@ def loadDB(): try: with open(dbname, "rb") as f: db = pickle.load(f) - except (ValueError, IOError): - log.exception("Relay: failed to load links database %s" - ", creating a new one in memory...", dbname) + except (ValueError, IOError, OSError): + log.info("Relay: failed to load links database %s" + ", creating a new one in memory...", dbname) db = {} def exportDB():