disnake icon indicating copy to clipboard operation
disnake copied to clipboard

fix: properly close sockets on voice server update

Open shiftinv opened this issue 3 years ago • 0 comments

Summary

Fixes #488.

It appears that quickly connecting to voice after another client connected results in 2 VOICE_SERVER_UPDATEs to be received. The connection is usually not fully established yet when the second one is received, which results in the warning + exception shown in the linked issue.

Code to reproduce:

async def on_voice_state_update(self, member, before, after: disnake.VoiceState):
    if member == member.guild.me:
        return
    ch = after.channel
    if not ch:
        return

    # uncommenting this avoids the duplicate `VOICE_SERVER_UPDATE`
    # import asyncio
    # await asyncio.sleep(1)
    await ch.connect()

Checklist

  • [x] If code changes were made, then they have been tested
    • [ ] I have updated the documentation to reflect the changes
    • [x] I have formatted the code properly by running task lint
    • [x] I have type-checked the code by running task pyright
  • [x] This PR fixes an issue
  • [ ] This PR adds something new (e.g. new method or parameters)
  • [ ] This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • [ ] This PR is not a code change (e.g. documentation, README, ...)

shiftinv avatar Jul 31 '22 17:07 shiftinv