Skip to content

Commit

Permalink
Fixed a hugely problematic bug that was causing the voice connection …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
baribarton committed Nov 5, 2024
1 parent b383e23 commit cd7ee38
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion discord/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cd7ee38

Please sign in to comment.