From cd7ee38c9e5d463edd225cda6c0910c0d9aff451 Mon Sep 17 00:00:00 2001 From: Jabari Date: Tue, 5 Nov 2024 01:47:49 -0800 Subject: [PATCH] Fixed a hugely problematic bug that was causing the voice connection to get stuck and never recover. I will have to do more work on voice client to make it more resilient to bugs like this --- discord/gateway.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/discord/gateway.py b/discord/gateway.py index 7a765405af..ebc2fd724d 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -896,7 +896,18 @@ async def initial_connection(self, data): struct.pack_into(">H", packet, 2, 70) # 70 = Length struct.pack_into(">I", packet, 4, state.ssrc) state.socket.sendto(packet, (state.endpoint_ip, state.voice_port)) - recv = await self.loop.sock_recv(state.socket, 74) + + try: + recv = await asyncio.wait_for(self.loop.sock_recv(state.socket, 74), timeout=2.0) + except asyncio.TimeoutError as e: + _log.error(f"Websocket Receive operation timed out. This can happen due to malformed data. {e}") + _log.debug(f"Problematic packet: {packet}") + raise e + except OSError as e: + _log.error(f"Websocket Receive operation encountered an OSError: {e}") + _log.debug(f"Problematic packet: {packet}") + raise e + _log.debug("received packet in initial_connection: %s", recv) # the ip is ascii starting at the 8th byte and ending at the first null