fixed deadlock when client disconnecting

This commit is contained in:
David Zhao
2020-12-05 22:20:13 -08:00
parent 71a7914eec
commit 2b9fee45c4
4 changed files with 30 additions and 12 deletions
+7 -4
View File
@@ -106,10 +106,13 @@ func (r *Room) RemoveParticipant(id string) {
defer r.lock.Unlock()
if p, ok := r.participants[id]; ok {
// also stop connection if needed
p.Close()
// update clients
r.broadcastParticipantState(p)
// avoid blocking lock
go func() {
// also stop connection if needed
p.Close()
// update clients
r.broadcastParticipantState(p)
}()
}
delete(r.participants, id)