From 294cc5d73eab67aec70502e5298dd5cbd1c73da0 Mon Sep 17 00:00:00 2001 From: Kae Bartlett Date: Thu, 18 Jan 2024 04:06:32 +0000 Subject: [PATCH] Add sleep to creating a new session from invalidate --- novus/api/gateway/gateway.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/novus/api/gateway/gateway.py b/novus/api/gateway/gateway.py index c84d0754..31ecb461 100644 --- a/novus/api/gateway/gateway.py +++ b/novus/api/gateway/gateway.py @@ -654,9 +654,11 @@ async def heartbeat( wait = heartbeat_interval * random.random() log.info( ( - f"Starting heartbeat - initial {wait / 100:.2f}s, " - f"normally {heartbeat_interval / 100:.2f}s" - ) + "[%s] Starting heartbeat - initial %ss, " + "normally %ss" + ), + self.shard_id, format(wait / 100, ".2f"), + format(heartbeat_interval / 100, ".2f"), ) else: log.info( @@ -871,14 +873,18 @@ async def message_handler(self) -> None: return else: log.warning( - "[%s] Session invalidated - creating a new session", - self.shard_id, + ( + "[%s] Session invalidated (resumable: %s) - " + "creating a new session in 5s" + ), + self.shard_id, str(message).lower() ) try: await asyncio.wait_for(self.close(), timeout=5) except asyncio.CancelledError: pass - t = asyncio.create_task(self.connect()) + await asyncio.sleep(5) + t = asyncio.create_task(self.connect(reconnect=message)) self.running_tasks.add(t) t.add_done_callback(self.running_tasks.discard) return # Cancel this task so a new one will be created