Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Race condition in voice connection flow #2056
There was a report of an unusual voice related error.
Task exception was never retrieved future: <Task finished coro=<VoiceClient._create_socket() done, defined at /usr/local/lib/python3.7/site-packages/discord/voice_client.py:168> exception=AttributeError("'NoneType' object has no attribute 'close'")> Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/discord/voice_client.py", line 195, in _create_socket await self.ws.close(4000) AttributeError: 'NoneType' object has no attribute 'close'
At first glance this looks a bit odd and upon further inspection it looks downright peculiar. Apparently
This is all happening while the user is trying to create a VoiceClient object via
voice = VoiceClient(state=state, timeout=timeout, channel=self) state._add_voice_client(key_id, voice) try: await voice.connect(reconnect=reconnect) except asyncio.TimeoutError: ...
The issue here is the time between adding the VoiceClient+key and
For this error to occur, a VoiceClient needs to be in the process of connecting, before the
To me, this seems like the combination of a very close race condition combined with Discord's signature Eventual Consistency™. A second
As for how to fix this, I have two possible ideas at the moment:
Once I do some testing to see if I can reproduce this I will see if I can come up with a suitable fix.