diff options
| author | Imayhaveborkedit <[email protected]> | 2019-04-10 00:17:12 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-04-10 00:55:52 -0400 |
| commit | 7eb8417883ffb869187554938165cf111e8a1e38 (patch) | |
| tree | 752925258592c5fe610f1ac20fb50be30dc6eebe | |
| parent | Add notes warning that fetch_ methods are api calls (diff) | |
| download | discord.py-7eb8417883ffb869187554938165cf111e8a1e38.tar.xz discord.py-7eb8417883ffb869187554938165cf111e8a1e38.zip | |
Fix voice handshake race condition
In the event that two voice_server_updates are received in a short time frame, the second one is now ignored.
| -rw-r--r-- | discord/voice_client.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/discord/voice_client.py b/discord/voice_client.py index 82affab4..be7a4d69 100644 --- a/discord/voice_client.py +++ b/discord/voice_client.py @@ -100,6 +100,9 @@ class VoiceClient: self._state = state # this will be used in the AudioPlayer thread self._connected = threading.Event() + + self._handshaking = False + self._handshake_check = asyncio.Lock(loop=self.loop) self._handshake_complete = asyncio.Event(loop=self.loop) self.mode = None @@ -166,6 +169,12 @@ class VoiceClient: self._state._remove_voice_client(key_id) async def _create_socket(self, server_id, data): + async with self._handshake_check: + if self._handshaking: + log.info("Ignoring voice server update while handshake is in progress") + return + self._handshaking = True + self._connected.clear() self.session_id = self.main_ws.session_id self.server_id = server_id @@ -209,6 +218,7 @@ class VoiceClient: try: self.ws = await DiscordVoiceWebSocket.from_client(self) + self._handshaking = False self._connected.clear() while not hasattr(self, 'secret_key'): await self.ws.poll_event() |