Add lock to prevent race condition (#816)

There's a race between `VoiceConnection.Disconnect()` and `VoiceConnection.onVoiceStateUpdate()` (accessing VoiceConnection.sessionID)
This commit is contained in:
Jonathan Roth 2020-11-15 21:55:36 +02:00 committed by GitHub
parent 92c52f3db1
commit 9bcbfecf1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()