Skip to content

Commit d348842

Browse files
committed
Fixed a hugely problematic bug that was causing the voice connection to get stuck and never recover. (#7)
I will have to do more work on voice client to make it more resilient to bugs like this
1 parent 753b239 commit d348842

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

discord/gateway.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,18 @@ async def initial_connection(self, data):
907907
struct.pack_into(">H", packet, 2, 70) # 70 = Length
908908
struct.pack_into(">I", packet, 4, state.ssrc)
909909
state.socket.sendto(packet, (state.endpoint_ip, state.voice_port))
910-
recv = await self.loop.sock_recv(state.socket, 74)
910+
911+
try:
912+
recv = await asyncio.wait_for(self.loop.sock_recv(state.socket, 74), timeout=2.0)
913+
except asyncio.TimeoutError as e:
914+
_log.error(f"Websocket Receive operation timed out. This can happen due to malformed data. {e}")
915+
_log.debug(f"Problematic packet: {packet}")
916+
raise e
917+
except OSError as e:
918+
_log.error(f"Websocket Receive operation encountered an OSError: {e}")
919+
_log.debug(f"Problematic packet: {packet}")
920+
raise e
921+
911922
_log.debug("received packet in initial_connection: %s", recv)
912923

913924
# the ip is ascii starting at the 8th byte and ending at the first null

0 commit comments

Comments
 (0)