3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00

Irc: move PYLINK_DISCONNECT firing and connected.clear() into disconnect() (#421)

This may prevent extra irc.connected.clear() calls from messing with the was_connected state.
This commit is contained in:
James Lu 2017-02-25 22:06:43 -08:00
parent 6fcb129ad6
commit 4df8567fa6
2 changed files with 7 additions and 5 deletions

View File

@ -105,7 +105,6 @@ class Irc():
self.pingfreq = self.serverdata.get('pingfreq') or 90
self.pingtimeout = self.pingfreq * 3
self.connected.clear()
self.pseudoclient = None
self.lastping = time.time()
@ -319,12 +318,8 @@ class Irc():
log.error('(%s) Disconnected from IRC: %s: %s',
self.name, type(e).__name__, str(e))
was_successful = self.connected.is_set()
self.disconnect()
# Internal hook signifying that a network has disconnected.
self.callHooks([None, 'PYLINK_DISCONNECT', {'was_successful': checks_ok and was_successful}])
# If autoconnect is enabled, loop back to the start. Otherwise,
# return and stop.
autoconnect = self.serverdata.get('autoconnect')
@ -343,6 +338,8 @@ class Irc():
def disconnect(self):
"""Handle disconnects from the remote server."""
was_successful = self.connected.is_set()
log.debug('(%s) disconnect: got %s for was_successful state', self.name, was_successful)
log.debug('(%s) disconnect: Clearing self.connected state.', self.name)
self.connected.clear()
@ -366,6 +363,9 @@ class Irc():
log.debug('(%s) disconnect: Setting self.aborted to True.', self.name)
self.aborted.set()
# Internal hook signifying that a network has disconnected.
self.callHooks([None, 'PYLINK_DISCONNECT', {'was_successful': was_successful}])
log.debug('(%s) disconnect: Clearing state via initVars().', self.name)
self.initVars()

View File

@ -1509,9 +1509,11 @@ def handle_disconnect(irc, numeric, command, args):
# Announce the disconnects to every leaf channel where the disconnected network is the owner
announcement = conf.conf.get('relay', {}).get('disconnect_announcement')
log.debug('(%s) relay: last connection successful: %s', irc.name, args.get('was_successful'))
if announcement and args.get('was_successful'):
with db_lock:
for chanpair, entrydata in db.items():
log.debug('(%s) relay: Looking up %s', irc.name, chanpair)
if chanpair[0] == irc.name:
for leaf in entrydata['links']:
log.debug('(%s) relay: Announcing disconnect to %s%s', irc.name,