Reconnect correctly after ping timeouts

This commit is contained in:
dave 2017-11-16 19:51:56 -08:00
parent 9b64dc3995
commit b142c501e7
3 changed files with 12 additions and 7 deletions

View File

@ -88,13 +88,14 @@ class IRCCore(object):
logging.info("Reconnecting in 3s...")
await asyncio.sleep(3)
async def kill(self, message="Help! Another thread is killing me :("):
async def kill(self, message="Help! Another thread is killing me :(", forever=True):
"""Send quit message, flush queue, and close the socket
:param message: Quit message to send before disconnecting
:type message: str
"""
self.alive = False
if forever:
self.alive = False
self.act_QUIT(message) # TODO will this hang if the socket is having issues?
await self.writer.drain()
self.writer.close()

View File

@ -59,6 +59,6 @@ class PingRespondTimer(Thread):
sleep(5)
if time() - self.lastping > self.master.config.get("activity_timeout", 300):
self.master.log.info("No activity in %s seconds. Reconnecting" % str(time() - self.lastping))
self.master.bot.disconnect("Reconnecting...")
self.master.bot.kill("Ping timeout", forever=False)
self.reset()

View File

@ -92,16 +92,20 @@ class PyIRCBot(object):
self.log.info("disconnect")
self.kill(message=message)
def kill(self, message="Help! Another thread is killing me :("):
"""Shut down the bot violently
def break_connection(self):
"""Break the connection, e.g. in the case of an unresponsive server"""
def kill(self, message="Help! Another thread is killing me :(", forever=True):
"""Close the connection violently
:param sys_exit: True causes sys.exit(0) to be called
:type sys_exit: bool
:param message: Quit message
:type message: str
"""
self.closeAllModules()
asyncio.run_coroutine_threadsafe(self.irc.kill(message=message), self.loop)
if forever:
self.closeAllModules()
asyncio.run_coroutine_threadsafe(self.irc.kill(message=message, forever=forever), self.loop)
def initModules(self):
"""load modules specified in instance config"""