discord.js
discord.js copied to clipboard
VoiceConnection disconnects after roughly 1 minute every time on WSL2
Which package is this bug report for?
voice
Issue description
I created a music bot while following the most recent guide and the voice connection dies out at around the same time. No errors are thrown.
After roughly one minute the voiceConnection changes state from connecting to signaling and freezes indefinitely until I restart, sometimes the bot doesn't even disconnect. Please ignore the ytdl
package, I have tested this with a normal local file and it does the same thing.
I've logged the state changes because those are the only things that change, as I said no errors are thrown and voiceConnection decides to change from Ready
to Connecting
to Signalling
and stays that way.
The project can be found at https://github.com/Beriu/boomtsy
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.11.0
- prism-media: 1.3.4
Opus Libraries
- @discordjs/opus: 0.8.0
- opusscript: 0.0.8
Encryption Libraries
- sodium-native: 3.4.1
- sodium: 3.0.2
- libsodium-wrappers: 0.7.10
- tweetnacl: 1.0.3
FFmpeg
- version: 5.0.1-static https://johnvansickle.com/ffmpeg/
- libopus: yes
--------------------------------------------------
Code sample
Bot is running...
Trying to create new voice connection: 777883619157999646
[17:11:13][VoiceConnection][signalling->connecting]
[17:11:13][VoiceConnection][connecting->connecting]
[17:11:13][VoiceConnection][connecting->connecting]
[17:11:13][VoiceConnection][connecting->connecting]
[17:11:13][VoiceConnection][connecting->ready]
[17:11:13][VoiceConnection][ready->ready]
Add command Queue size: 0
Start command Queue size: 1
[17:11:15][AudioPlayer][idle->buffering]
[17:11:15][AudioPlayer][buffering->playing]
[17:12:13][VoiceConnection][ready->connecting]
[17:12:13][AudioPlayer][playing->idle]
[17:12:13][VoiceConnection][connecting->signalling]
Package version
14.2.1
Node.js version
v16.16.0 (Typescript 4.7.4)
Operating system
WSL 2 (Windows subsystem for Linux, Ubuntu)
Priority this issue should have
Low (slightly annoying)
Which partials do you have configured?
No Partials
Which gateway intents are you subscribing to?
Guilds, GuildVoiceStates
I have tested this issue on a development release
c97977a
I got the same problem. This issue should be marked higher than Low Priority imho. (Also WSL2)
I just confirmed that this disconnect after roughly 55 seconds is only on WSL2 systems. It has nothing to do with the streaming, it is something wrong with discord.js/voice
I would be very grateful if this gets fixed! :)
I might have something that you guys should give a try,
Uninstall August and July cumulative and security updates on Windows 10 (unsure which KB is Win11). KB5016616, KB5012170, KB5015811
It seems that either the July update (KB5015811) or August update (the other two) messed with how the WSL Ethernet adapter handles certain connections.
I am not an expert in this, so I cannot comment further, but from capturing the packets, the initial TLS handshake works and then voice UDP connection is enacted. After about 1 minute~ish, it attempts another TLS handshake with Discord and fails.
I've been experiencing the same issue on my Linux ubuntu service VM. Bot can run for hours on windows with no issue, but every time i try on linux it just stops after a min or so.
I've had it setup with discord.js v12 for many years with no issues, but the recent update to v13, and now v14 seems to have started the issue. That being said it could also be any VM system update as well.
EDIT: I mainly needed it to work for short clips like memes and TTS. So the way i solved it were just to run
getVoiceConnection(guildId).configureNetworking()
before any play action, that would make it work for the next 1 min.
I later created a watch together feature that send you to a link where the video played synced with the discord sound, but that also experienced a 1 min cutoff issue. It was hosted on another Linux VM hosted on the same windows server. So I'm highly suspecting this to be a Linux distro issue, or at least windows Linux hosting issue.
I too am experiencing this exact issue. Also using WSL 2 on Windows 11.
Did anyone find a workaround for this? I've been banging my head against it all day :'(
I have no idea how but somehow removing my node installation and reinstalling it fixed the issue. I thought maybe the issue was related to the LTS version of node (v16.17.1 as of this comment) so I tried Node v18.10 and the problem went away. I was about to post here that it was the node version but then I thought I better go back and try v16.17.1 again. Sure enough no issue...
All I can do is speculate about what might have fixed it. I had a few things installed globally as well as locally in the project such as typescript
, ts-node
, and nodemon
. Small possibility some weird interaction was happening there maybe? I think I had tried re-installing project dependencies a couple times today, but I'm so bleary-eyed at this point that I'm wondering if I neglected to actually try just blowing away node_modules
before blowing away the whole node installation. So maybe try simply re-installing project dependencies if you haven't yet. If that doesn't work then try re-installing the whole node installation.
I really don't know, it went away for me after installing the latest windows updates, I'm on build 19044.2075
but I also bumped Node to version 18, seems to work now.
I will try to run the bot on Ubuntu server on my RasberryPi to see if it stops working there
I'm facing the same problem both on my RPi and my computer on Ubuntu 22.10, andafter changing versions of node and reinstalling dependencies, it still doesn't work properly
Same issue on debian and centos linux on dedicated hostes ionos
After doing random sh*t on the code of discordjs/voice it seems to works adding this.configureNetworking();
on the line 355 of this file : https://github.com/discordjs/discord.js/blob/main/packages/voice/src/VoiceConnection.ts
Or on the line ~~1363~~ 1361 of the file located at node_modules/@discordjs/voice/dist/index.js
I don't exactly know what I've done but as far as it works it's enough for me π Edit : I can hear a blank in the sound sometimes but that's far better than a complete stop
Since yesterday same thing started happening to me and my bot. Tried switching versions, tried completely wiping and reinstalling NodeJS (even different versions). Tried switching OS, tried on my VPS with Debian, tried on my main PC with Ubuntu and tried lunching under Windows both natively and under WSL2. Same problem, around 55~65 seconds bot's voice connection stops and after a few seconds disconnects, with no error message or anything. Even debugging doesn't resolve it.
Theiremi's fix works, but it's not really an "official" solution. Is there anything that can be done about this problem?
I suspect the bug to come with an update on my server, but if it's not the cause, that's probably a bug in discord that is not well handled by discord.js
Same thing occurs here. Numbers are similar too. 55-65 second always on time. Changing VoiceConnection.ts results that audio not cut completely but stops for 2-3 second then resume afterwards. Tried on different computers. Same issue. Tried with different node.js versions same issue. Tried ytdl-core and play-dl for streaming same issue. Looks like issue related with the discordjs or discordjs/voice
Idk if I understand correctly the code, but it seems that discord.js is expecting a packet from discord api (called server packet in code) and never receive it, so it stay in signalling state because this packet is the only thing that can let it continue the voice connection
Let's create a new issue. The current bug has the same symptoms but not the same cause, the old bug was a WSL2 issue. This, on the other hand, acts indiscriminately, not depending on OS (or node version, discord.js version, @discordjs/voice version, type of input stream, or anything else I thought of testing in the last few hours.). We really need to get some proper staff to see this.
same thing here, the music plays for a bit then stops. Anyone have a good fix for this, its badly needed as my bot is verified lmao and I'm the only person working on it
same thing here, the music plays for a bit then stops. Anyone have a good fix for this, its badly needed as my bot is verified lmao and I'm the only person working on it
You can do this fix: link Also check out this new issue with a fix the guild admins can implement: link
thats fine only put it under addStatePacket(packet) { this.configureNetworking();
Have same issue Till an official solution is introduced I recommend using npm patch package https://www.npmjs.com/package/patch-package
This guide may be helpful: https://dev.to/zhnedyalkow/the-easiest-way-to-patch-your-npm-package-4ece
remember to patch:
npx patch-package @discordjs/voice
My node_modules/@discordjs/voice/dist/index.js is all stacked together. Could anyone help me understand where to insert the line?
I also tried to modify https://github.com/discordjs/discord.js/blob/main/packages/voice/src/VoiceConnection.ts, but I don't exactly know how to patch a forked repo. Any help would be appreciated. Thanks!
My node_modules/@discordjs/voice/dist/index.js is all stacked together. Could anyone help me understand where to insert the line? I also tried to modify
main
/packages/voice/src/VoiceConnection.ts, but I don't exactly know how to patch a forked repo. Any help would be appreciated. Thanks!
Seems like you're on an outdated voice version, we haven't released minified builds for at least 1-2 versions
My node_modules/@discordjs/voice/dist/index.js is all stacked together. Could anyone help me understand where to insert the line? I also tried to modify
main
/packages/voice/src/VoiceConnection.ts, but I don't exactly know how to patch a forked repo. Any help would be appreciated. Thanks!Seems like you're on an outdated voice version, we haven't released minified builds for at least 1-2 versions
Thanks. Turned out my voice version is indeed very old and updating to latest ver correctly shows the good version. Thanks.
Hi guys. I have the exact issue. After spending sometime tshooting, i found out that the bot goes to signalling state after trying to reach a discord gateway for the 2ΒΊ time, before the previous socket is closed:
I hope this helps on the fix.
This is just speculation, but it seems discord updated something on the network side, the frequency of the "keep-alive" checks from the gateway to the bot. The current package can't handle the keep-alive properly because the socket isn't expecting a new connection after the initial check.
Cheers
After doing random sh*t on the code of discordjs/voice it seems to works adding
this.configureNetworking();
on the line 355 of this file : https://github.com/discordjs/discord.js/blob/main/packages/voice/src/VoiceConnection.ts Or on the line ~1363~ 1361 of the file located at node_modules/@discordjs/voice/dist/index.js
This solution solved it for me @Theiremi, tks a lot!
After doing random sh*t on the code of discordjs/voice it seems to works adding
this.configureNetworking();
on the line 355 of this file : https://github.com/discordjs/discord.js/blob/main/packages/voice/src/VoiceConnection.ts Or on the line ~1363~ 1361 of the file located at node_modules/@discordjs/voice/dist/index.jsThis solution solved it for me @Theiremi, tks a lot!
You shound also check this fix which works way better than mine as it removes the part of the discordjs code that create the issue π
Is there any viable solution for discord.js version 13.6.0? My voice version is scrambled or something.
Try reinstall your @discord/voice it will fix the issue. I was facing same issue on discord Indian voice server. I had reinstalled @discord/voice and now it's works fine.