Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shard): handle RECONNECT opcode during initial connection flow #1155

Merged
merged 3 commits into from Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1155.bugfix.rst
@@ -0,0 +1 @@
Handle unexpected ``RECONNECT`` opcode where ``HELLO`` is expected during initial shard connection.
18 changes: 18 additions & 0 deletions disnake/shard.py
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