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:
parent
92c52f3db1
commit
9bcbfecf1d
1 changed files with 2 additions and 0 deletions
2
voice.go
2
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()
|
||||
|
|
Loading…
Reference in a new issue