Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VoiceConnection stuck in signalling state about a minute after creating it #9185

Closed
Theiremi opened this issue Mar 1, 2023 · 63 comments
Closed

Comments

@Theiremi
Copy link

Theiremi commented Mar 1, 2023

Which package is this bug report for?

voice

Issue description

I've noticed a bug that seems to affect also some other users (see #8482).
All the VoiceConnection works as intended the first minute, and then stop playing anything. The player subscribed switch in AutoPaused and the connection stays signalling state indefinitely.

After looking at the code (https://github.com/discordjs/discord.js/blob/main/packages/voice/src/VoiceConnection.ts), it seems that the only way for it to go back to ready state is to receive a message from discord api, that then create events that can put status back in ready state.
But, if I understand correctly, this discord message never comes(line 335), so an event is not created through the function configureNetworking(line 338, 420), and the state cannot change to ready(line 484).
That's a messy explanation, and maybe false btw, but I've tried my best to understand.

Code sample

let voice_connection = Voice.joinVoiceChannel({
	adapterCreator: guild.voiceAdapterCreator,
	guildId: guild_id,
	channelId: channel_id,
	selfDeaf: true,
	selfMute: false
});

let player = new Voice.AudioPlayer({noSubscriber: Voice.NoSubscriberBehavior.Pause});
voice_connection.subscribe(player);

let resource = Voice.createAudioResource(local_file_or_stream);
player.play(resource);

Package version

14.7.0

Node.js version

18.7.0; 18.14.2; 19.7.0 and maybe others

Operating system

Windows, WSL, Ubuntu, Debian...

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

Not applicable (subpackage bug)

Which gateway intents are you subscribing to?

Guilds, GuildVoiceStates

I have tested this issue on a development release

No response

@Theiremi
Copy link
Author

Theiremi commented Mar 1, 2023

I've also found a workaround to this problem :

Add this.configureNetworking(); on the line 355 of this file : https://github.com/discordjs/discord.js/blob/main/packages/voice/src/VoiceConnection.ts
Or
Add this.configureNetworking(); on the line 1361 of the file located at node_modules/@discordjs/voice/dist/index.js

@FloPMT
Copy link

FloPMT commented Mar 1, 2023

I've also found a workaround to this problem :

Add this.configureNetworking(); on the line 355 of this file : https://github.com/discordjs/discord.js/blob/main/packages/voice/src/VoiceConnection.ts Or Add this.configureNetworking(); on the line 1361 of the file located at node_modules/@discordjs/voice/dist/index.js

Thank you! This sort of helps as it seems to restart the stream after a few seconds of it being autopaused. But that's not really a solution where I'd create a PR because the stream still stops after each minute.
What's weird is that even with noSubscriber: NoSubscriberBehavior.Play it pauses playback. Just the status doesn't update and remains "playing".

image

@potatojuicemachine
Copy link

I have the same problem. It started to happen today without me changing anything in the code. So probably discord changing something on their side of the connection 🤔.
@Theiremi your solution works for me but now i have a short pause every minute while playling.

@vittee
Copy link

vittee commented Mar 1, 2023

I have the exact same issue, after trying to figure out what could possibly be the problem I found that this happen only on some voice servers.

I was trying to override voice channel region between Singapore and Hong Kong. The problem will not occur if the channel endpoint has the number greater than around 10,000

e.g.
singapore1172 -> Has problem
singapore4221 -> Has problem
singapore11001 -> Working just fine

You can enable debugging in VoiceConnection by setting debug field to true when calling joinVoiceChannel() function

const voiceConnection = joinVoiceChannel({
  debug: true,
  channelId,
  guildId,
  adapterCreator: voiceAdapterCreator
});

voiceConnection.on('debug', (m) => {
  console.log('Voice Debug:', m);
});

I got this debug message when the connection was closed

Voice Debug: [NW] state change:
from {"code":4,"ws":true,"connectionOptions":{"endpoint":"singapore4221.discord.media:443"},"udp":true,"speaking":true,"packetsPlayed":2996}}
to {"code":5,"ws":true,"connectionOptions":{"endpoint":"singapore4221.discord.media:443"},"udp":true},"speaking":true,"packetsPlayed":2996}}


Voice Debug: [NW] [WS] >> {"op":7,"d":{...}}
Voice Debug: [NW] [WS] << {"op":8,"d":{"v":4,"heartbeat_interval":13750.0}}


Voice Debug: [NW] state change:
from {"code":5,"ws":true,"connectionOptions":{"endpoint":"singapore4221.discord.media:443"},"udp":true,"speaking":true,"packetsPlayed":2996}}}
to {"code":6,"ws":false,"udp":false}

Networking status code 4 is "Ready", 5 is "Resuming" and 6 is "Closed"

After looking at VoiceConnection code:
https://github.com/discordjs/discord.js/blob/main/packages/voice/src/VoiceConnection.ts#L442-L467

I can see that it handles disconnection properly but somehow re-signalling/rejoining is not working as expected.

The solution I could find right now is try to override server region to other regions until you get a voice server with number greater than 10,000 in its name, but the server will change again if the channel is empty.

@Theiremi
Copy link
Author

Theiremi commented Mar 1, 2023

I've noticed a pause too, i guess there is a problem on discord side causing the connection to crash every minute. The pause happens during the time needed to reconnect so we probably can't get better solution for now 😥

@Theiremi
Copy link
Author

Theiremi commented Mar 1, 2023

I have the exact same issue, after trying to figure out what could possibly be the problem I found that this happen only on some voice servers.

I was trying to override voice channel region between Singapore and Hong Kong. The problem will not occur if the channel endpoint has the number greater than around 10,000

e.g. singapore1172 -> Has problem singapore4221 -> Has problem singapore11001 -> Working just fine

You can enable debugging in VoiceConnection by setting debug field to true when calling joinVoiceChannel() function

const voiceConnection = joinVoiceChannel({
  debug: true,
  channelId,
  guildId,
  adapterCreator: voiceAdapterCreator
});

voiceConnection.on('debug', (m) => {
  console.log('Voice Debug:', m);
});

I got this debug message when the connection was closed

Voice Debug: [NW] state change:
from {"code":4,"ws":true,"connectionOptions":{"endpoint":"singapore4221.discord.media:443"},"udp":true,"speaking":true,"packetsPlayed":2996}}
to {"code":5,"ws":true,"connectionOptions":{"endpoint":"singapore4221.discord.media:443"},"udp":true},"speaking":true,"packetsPlayed":2996}}


Voice Debug: [NW] [WS] >> {"op":7,"d":{...}}
Voice Debug: [NW] [WS] << {"op":8,"d":{"v":4,"heartbeat_interval":13750.0}}


Voice Debug: [NW] state change:
from {"code":5,"ws":true,"connectionOptions":{"endpoint":"singapore4221.discord.media:443"},"udp":true,"speaking":true,"packetsPlayed":2996}}}
to {"code":6,"ws":false,"udp":false}

Networking status code 4 is "Ready", 5 is "Resuming" and 6 is "Closed"

After looking at VoiceConnection code: https://github.com/discordjs/discord.js/blob/main/packages/voice/src/VoiceConnection.ts#L442-L467

I can see that it handles disconnection properly but somehow re-signalling/rejoining is not working as expected.

The solution I could find right now is try to override server region to other regions until you get a voice server with number greater than 10,000 in its name, but the server will change again if the channel is empty.

Interesting, it seems to confirm that the issue is coming from discord

@vittee
Copy link

vittee commented Mar 1, 2023

I tried to override my voice channel to Singapore and I got singapore11014. It is working just fine, no disconnection at all.

@FloPMT
Copy link

FloPMT commented Mar 1, 2023

I tried to override my voice channel to Singapore and I got singapore11014. It is working just fine, no disconnection at all.

Could you share how you do it? Thanks!

@Theiremi
Copy link
Author

Theiremi commented Mar 1, 2023

Do you know if overriding the server region can only be done by end users or if it's possible to make a patch in our bots too ?

@vittee
Copy link

vittee commented Mar 1, 2023

I think you must have administrative permission on the server you want to override and it can only be done via Discord app itself.

image

image

@Theiremi
Copy link
Author

Theiremi commented Mar 1, 2023

Ok so i've made an announce in my server linking to your solution to help end users

@Jiralite
Copy link
Member

Jiralite commented Mar 1, 2023

I believe this was a Discord issue that should be resolved now. Can you guys check (on a new connection, if possible (restart your bot)) if you can still reproduce this?

@FloPMT
Copy link

FloPMT commented Mar 1, 2023

I think you must have administrative permission on the server you want to override and it can only be done via Discord app itself.

image

image

I found that it's possible programmatically with the right permissions:
voiceChannel.setRTCRegion('singapore');

This doesn't fix the problem for me however.

@FloPMT
Copy link

FloPMT commented Mar 1, 2023

I believe this was a Discord issue that should be resolved now. Can you guys check (on a new connection, if possible (restart your bot)) if you can still reproduce this?

Unfortunately still have the same issue.

@potatojuicemachine
Copy link

I wasn't able to switch the region on the server so I made this as a temporary workaround:

this.connection.on('stateChange', (old_state, new_state) => {
            this.logger.logMessage('join', 'Connection state change from', old_state.status, 'to', new_state.status)
            if (old_state.status === VoiceConnectionStatus.Ready && new_state.status === VoiceConnectionStatus.Connecting) {
                connection.configureNetworking();
            }
        })

The little pause is shorter then on this solution.
Maybe this helps anyopne looking for a temporary solution.

@vittee
Copy link

vittee commented Mar 1, 2023

I think you must have administrative permission on the server you want to override and it can only be done via Discord app itself.
image
image

I found that it's possible programmatically with the right permissions: voiceChannel.setRTCRegion('singapore');

This doesn't fix the problem for me however.

Thanks, would try that.

BTW, overriding the region to Singapore does not fix the problem, you need to keep changing it until you get server which has number greater than 10,000 in its name.

This one is working fine for me
image

@Theiremi
Copy link
Author

Theiremi commented Mar 1, 2023

I believe this was a Discord issue that should be resolved now. Can you guys check (on a new connection, if possible (restart your bot)) if you can still reproduce this?

I can't test on a fresh instance for now, but still happens for me too

@Theiremi
Copy link
Author

Theiremi commented Mar 1, 2023

I wasn't able to switch the region on the server so I made this as a temporary workaround:

this.connection.on('stateChange', (old_state, new_state) => {
            this.logger.logMessage('join', 'Connection state change from', old_state.status, 'to', new_state.status)
            if (old_state.status === VoiceConnectionStatus.Ready && new_state.status === VoiceConnectionStatus.Connecting) {
                connection.configureNetworking();
            }
        })

The little pause is shorter then on this solution. Maybe this helps anyopne looking for a temporary solution.

That's actually also a much simpler solution as it doesn't require modifying module code 😄

@vittee
Copy link

vittee commented Mar 1, 2023

I believe this was a Discord issue that should be resolved now. Can you guys check (on a new connection, if possible (restart your bot)) if you can still reproduce this?

Still happens on singapore8142, but works fine on singapore11014

@potatojuicemachine
Copy link

I believe this was a Discord issue that should be resolved now. Can you guys check (on a new connection, if possible (restart your bot)) if you can still reproduce this?

Restarted my bot several times. Still same issue.

@YenBenGrey
Copy link

I wasn't able to switch the region on the server so I made this as a temporary workaround:

this.connection.on('stateChange', (old_state, new_state) => {
            this.logger.logMessage('join', 'Connection state change from', old_state.status, 'to', new_state.status)
            if (old_state.status === VoiceConnectionStatus.Ready && new_state.status === VoiceConnectionStatus.Connecting) {
                connection.configureNetworking();
            }
        })

The little pause is shorter then on this solution. Maybe this helps anyopne looking for a temporary solution.

That's actually also a much simpler solution as it doesn't require modifying module code 😄

Imagine you have no idea about how to write code? Where would you put this so that things work again in Discord?

DanielBUBU added a commit to DanielBUBU/PD_maid that referenced this issue Mar 9, 2023
- Sending less GUI
- fix the bug for discordjs:discordjs/discord.js#9185 (comment)
- prepare for the web GUI
DanielBUBU added a commit to DanielBUBU/PD_maid that referenced this issue Mar 9, 2023
- Sending less GUI
- fix the bug for discordjs:discordjs/discord.js#9185 (comment)
- prepare for the web GUI
DanielBUBU added a commit to DanielBUBU/PD_maid that referenced this issue Mar 9, 2023
- Sending less GUI
- fix the bug for discordjs:discordjs/discord.js#9185 (comment)
- prepare for the web GUI
brandon-doornbos added a commit to brandon-doornbos/vibin that referenced this issue Mar 10, 2023
DavidCarbon added a commit to DavidCarbon/evobot that referenced this issue Mar 11, 2023
benjamonnguyen added a commit to benjamonnguyen/pomomo-rewrite that referenced this issue Mar 12, 2023
benjamonnguyen added a commit to benjamonnguyen/pomomo-rewrite that referenced this issue Mar 12, 2023
benjamonnguyen added a commit to benjamonnguyen/pomomo-rewrite that referenced this issue Mar 12, 2023
@vittee
Copy link

vittee commented Mar 12, 2023

This has been fixed in v0.15.0
https://github.com/discordjs/discord.js/blob/%40discordjs%2Fvoice%400.15.0/packages/voice/CHANGELOG.md

@vladfrangu
Copy link
Member

Indeed it has been fixed! Slap that npm i @discordjs/voice@latest in your terminal and (assuming npm cache doesn't troll you and installs 0.14.0 still) it'll be all gud!

@Xlizer1
Copy link

Xlizer1 commented Mar 22, 2023

I wasn't able to switch the region on the server so I made this as a temporary workaround:

this.connection.on('stateChange', (old_state, new_state) => {
            this.logger.logMessage('join', 'Connection state change from', old_state.status, 'to', new_state.status)
            if (old_state.status === VoiceConnectionStatus.Ready && new_state.status === VoiceConnectionStatus.Connecting) {
                connection.configureNetworking();
            }
        })

The little pause is shorter then on this solution. Maybe this helps anyopne looking for a temporary solution.

That's actually also a much simpler solution as it doesn't require modifying module code 😄

so i have to add it to this file? /discor-music-player/dist/managers/Queue.js?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests