DisnakeDev / disnake

An API wrapper for Discord written in Python.
https://docs.disnake.dev
MIT License
718 stars 136 forks source link

bug: `await VoiceClient.disconnect()` raise `OSError: [WinError 10038]` when passing a str that represent a non file-like object #846

Open Snipy7374 opened 1 year ago

Snipy7374 commented 1 year ago

Summary

When using a FFmpegPCMAudio audio source with a source that represent a non file-like object (e.g a url) and when disconnecting from a VoiceChannel you get an OSError.

This bug was found while trying to test more

Reproduction Steps

Connect to a VoiceChannel Start playing something using FFmpegPCMAudio as audio source with a source that does't represent a file-like object Disconnect from the VoiceChannel using await VoiceClient.disconnect()

Minimal Reproducible Code

@bot.slash_command()
async def test(inter):
    channel: disnake.VoiceChannel = await bot.fetch_channel(874005538285977603)
    vc = await channel.connect()
    vc.play(disnake.FFmpegPCMAudio("https://github.com/ninjamuffin99/Funkin/blob/a083938ac803a91fbb15f03e432dea620f8a3b4a/assets/songs/bopeebo/Inst.mp3?raw=true", executable="C:\\Users\\user\\LMAOGOTIT\\Desktop\\ffmpeg-master-latest-win64-gpl-shared\\bin\\ffmpeg.exe"))
    print(f"playing: {vc.is_playing()} paused: {vc.is_paused()}")
    await asyncio.sleep(2)
    vc.stop()
    await vc.disconnect()

Expected Results

The bot should disconnect from the VoiceChannel succesfully without raising any error

Actual Results

The bot raise an error, full traceback below:

Exception in voice thread Thread-3
Traceback (most recent call last):
  File "C:\Coding prog\lib\site-packages\disnake\player.py", line 746, in run
    self._do_run()
  File "C:\Coding prog\lib\site-packages\disnake\player.py", line 739, in _do_run
    play_audio(data, encode=not self.source.is_opus())
  File "C:\Coding prog\lib\site-packages\disnake\voice_client.py", line 686, in send_audio_packet
    self.socket.sendto(packet, (self.endpoint_ip, self.voice_port))
OSError: [WinError 10038] an operation was attempted on something that is not a socket

Intents

Irrelevants

System Information

Windows 11 Version 21H2 -- Build SO 22000.1098
Disnake 2.7.0

Checklist

Additional Context

I think that the problem is related to the stream of bytes coming from FFmpeg or some bug/problem occurred while trying to stop the stream

shiftinv commented 1 year ago

Can't reproduce after several tries (Ubuntu 22.04, ffmpeg 4.4.2), how reliably does this occur for you? Sounds like a (fairly harmless) race condition, in any case.

Snipy7374 commented 1 year ago

Can't reproduce after several tries (Ubuntu 22.04, ffmpeg 4.4.2), how reliably does this occur for you? Sounds like a (fairly harmless) race condition, in any case.

mb, I think it probably only affects Windows users

tomorrow I'll update the issue with version informations

Snipy7374 commented 1 year ago

I've added System informations