Skip to content

Commit

Permalink
fix(shard): handle RECONNECT opcode during initial connection flow (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv authored Jan 20, 2024
1 parent 4da720d commit a24abf4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/1155.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle unexpected ``RECONNECT`` opcode where ``HELLO`` is expected during initial shard connection.
18 changes: 18 additions & 0 deletions disnake/shard.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ async def reidentify(self, exc: ReconnectWebSocket) -> None:
gateway=self.ws.resume_gateway if exc.resume else None,
)
self.ws = await asyncio.wait_for(coro, timeout=60.0)
# n.b. this is the same error handling as for the actual worker, but for the initial connect steps
except ReconnectWebSocket as e:
_log.debug(
"Unexpectedly received request to %s shard ID %s while attempting to %s",
e.op,
self.id,
exc.op,
)
etype = EventType.resume if e.resume else EventType.identify
self._queue_put(EventItem(etype, self, e))
except self._handled_exceptions as e:
await self._handle_disconnect(e)
except asyncio.CancelledError:
Expand All @@ -204,6 +214,14 @@ async def reconnect(self) -> None:
try:
coro = DiscordWebSocket.from_client(self._client, shard_id=self.id)
self.ws = await asyncio.wait_for(coro, timeout=60.0)
except ReconnectWebSocket as e:
_log.debug(
"Unexpectedly received request to %s shard ID %s while attempting to reconnect",
e.op,
self.id,
)
etype = EventType.resume if e.resume else EventType.identify
self._queue_put(EventItem(etype, self, e))
except self._handled_exceptions as e:
await self._handle_disconnect(e)
except asyncio.CancelledError:
Expand Down

0 comments on commit a24abf4

Please sign in to comment.