From 701720a0f802c20d283c197aa7ea9a74f628c0cb Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 6 May 2016 13:30:44 -0400 Subject: [PATCH] Add a TimeoutError if VoiceClient.connect fails. --- discord/client.py | 11 ++++++++++- discord/gateway.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/discord/client.py b/discord/client.py index 3d7b8afaa..f56f84bfc 100644 --- a/discord/client.py +++ b/discord/client.py @@ -2450,7 +2450,16 @@ class Client: } voice = VoiceClient(**kwargs) - yield from voice.connect() + try: + yield from voice.connect() + except asyncio.TimeoutError as e: + try: + yield from voice.disconnect() + except: + # we don't care if disconnect failed because connection failed + pass + raise e # re-raise + self.connection._add_voice_client(server.id, voice) return voice diff --git a/discord/gateway.py b/discord/gateway.py index 661607b2a..7ed7371be 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -553,7 +553,7 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol): @asyncio.coroutine def poll_event(self): try: - msg = yield from self.recv() + msg = yield from asyncio.wait_for(self.recv(), timeout=30.0, loop=self.loop) yield from self.received_message(json.loads(msg)) except websockets.exceptions.ConnectionClosed as e: raise ConnectionClosed(e) from e