-
Notifications
You must be signed in to change notification settings - Fork 831
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
Voice websocket closed unexpectedly at random times #829
Comments
I've been getting this and it's a real pain. No way to catch it or anything. For me at least, it doesn't always crash from it; only about half the time. Really hoping someone will give us an update. Even a basic |
I have an update on this one. Thanks to the @FlameInTheDark on this issue here, it appears that using this: vc, err := discord.ChannelVoiceJoin(guildID, channelID, properties.Muted, properties.Deafened)
if err != nil {
if _, ok := discord.VoiceConnections[guildID]; ok {
vc = discord.VoiceConnections[guildID]
} else {
return nil, err
}
} —will fix your issue. It almost looks like |
I'm trying using that code and it does not timeout even after an hour has passed. |
Temporary fix according to bwmarrin/discordgo#829
This doesn't seem to be working for me anymore. I haven't had a chance to double check and make sure I didn't screw something up, but I will as soon as I can. if err != nil {
log.Fatalln("error connecting:", err)
return // Emphasis on the return
} —at the end. This doesn't look like it'll fix the issue, but it might stop the crashing? We'll see. |
I've been thinking about this a lot, I think I should give the websocket a keepalive signal like below code. func DiscordVoicePing(guildID string) {
voiceConnection[guildID].StreamSession.SetPaused(true)
done := make(chan error)
encodingSession, _ := dca.EncodeFile("./bin/ping.mp3", options)
dca.NewStream(encodingSession, voiceConnection[guildID].VC, done)
err := <-done
if err != nil && err != io.EOF {
log.Printf("Ping Error: %s", err.Error())
}
voiceConnection[guildID].StreamSession.SetPaused(false)
}
|
Idiot me didn't realize that we were using vc, err = s.ChannelVoiceJoin(e.GuildID, e.ChannelID, false, false)
if err != nil {
if err, ok := s.VoiceConnections[e.GuildID]; ok {
vc = s.VoiceConnections[e.GuildID]
if err != nil {
log.Println("error connecting:", err)
return
}
} else {
log.Println("error connecting:", err)
return
}
} Will report back later. For anyone else who's interested, this is the line with the function that throws the error. Looks like just a simple loop waiting for it to |
Looks like the snippet I posted above does the trick. However, the error is still happening. This is what I've found: i := 0
for {
if v.sessionID != "" {
break
}
if i > 20 { // only loop for up to 1 second total
return fmt.Errorf("did not receive voice Session ID in time")
}
time.Sleep(50 * time.Millisecond)
i++
} The whole error down the chain being:
This is what I've found from the Discord docs:
So the bot is waiting on two packets, and it kinda looks like they're not arriving. Granted, it is only waiting 1 second. While the I'll try to fork it, make the change, and test it when I get the chance. In the mean time, anyone is welcome to try increasing the timeout from the line I mentioned above and reporting back. |
I had the same bug, but increasing the timeout had no effect. I realized it's a deadlock; See my PR mentioned above for the fix. |
I'm making a bot which is playing songs using github.com/jonas747/dca.
However it always leave the voice channel at random times (about after 1 hour) with below log and join the channel again.
My internet is stable and I even used Amazon AWS but it showed same problem.
The text was updated successfully, but these errors were encountered: