Skip to content

Commit

Permalink
Add sleep to creating a new session from invalidate
Browse files Browse the repository at this point in the history
  • Loading branch information
4Kaylum committed Jan 18, 2024
1 parent a8d2790 commit 294cc5d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions novus/api/gateway/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 294cc5d

Please sign in to comment.