From 9bcbfecf1d58e3727cb791c7ecb95b08bd419d3b Mon Sep 17 00:00:00 2001 From: Jonathan Roth Date: Sun, 15 Nov 2020 21:55:36 +0200 Subject: [PATCH] Add lock to prevent race condition (#816) There's a race between `VoiceConnection.Disconnect()` and `VoiceConnection.onVoiceStateUpdate()` (accessing VoiceConnection.sessionID) --- voice.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/voice.go b/voice.go index 586b783..dbafd83 100644 --- a/voice.go +++ b/voice.go @@ -139,6 +139,7 @@ func (v *VoiceConnection) ChangeChannel(channelID string, mute, deaf bool) (err func (v *VoiceConnection) Disconnect() (err error) { // Send a OP4 with a nil channel to disconnect + v.Lock() if v.sessionID != "" { data := voiceChannelJoinOp{4, voiceChannelJoinData{&v.GuildID, nil, true, true}} v.session.wsMutex.Lock() @@ -146,6 +147,7 @@ func (v *VoiceConnection) Disconnect() (err error) { v.session.wsMutex.Unlock() v.sessionID = "" } + v.Unlock() // Close websocket and udp connections v.Close()