Skip to content

Commit 58193fb

Browse files
fix(voice): session id deadlock on open (#1408)
* Unlock when checking voice connection sessionID to prevent deadlock * Move lock to preserve concurrency safety, while allowing the sessionID to be populated * style: formatting Fix formatting of the documentation comment for VoiceConnection.Speaking function * feat: reword explanatory comment --------- Co-authored-by: Fedor Lapshin <[email protected]>
1 parent 393091b commit 58193fb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

voice.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type VoiceSpeakingUpdateHandler func(vc *VoiceConnection, vs *VoiceSpeakingUpdat
7676
// Speaking sends a speaking notification to Discord over the voice websocket.
7777
// This must be sent as true prior to sending audio and should be set to false
7878
// once finished sending audio.
79-
// b : Send true if speaking, false if not.
79+
// b : Send true if speaking, false if not.
8080
func (v *VoiceConnection) Speaking(b bool) (err error) {
8181

8282
v.log(LogDebug, "called (%t)", b)
@@ -294,11 +294,15 @@ func (v *VoiceConnection) open() (err error) {
294294
if v.sessionID != "" {
295295
break
296296
}
297+
297298
if i > 20 { // only loop for up to 1 second total
298299
return fmt.Errorf("did not receive voice Session ID in time")
299300
}
301+
// Release the lock, so sessionID can be populated upon receiving a VoiceStateUpdate event.
302+
v.Unlock()
300303
time.Sleep(50 * time.Millisecond)
301304
i++
305+
v.Lock()
302306
}
303307

304308
// Connect to VoiceConnection Websocket

0 commit comments

Comments
 (0)