Fix clientsMtx lock without unlock in Broadcast()

Reorganize the lock/unlock pairs to be more consistent and to fix a
case with an uneven lock/unlock.
This commit is contained in:
Zorchenhimer 2019-03-24 16:38:42 -04:00
parent 2f252d5ae8
commit 60f3ade2ee
1 changed files with 4 additions and 1 deletions

View File

@ -330,6 +330,10 @@ func (cr *ChatRoom) Broadcast() {
// Only send Chat and Event stuff to temp clients
if msg.Type != common.DTChat && msg.Type != common.DTEvent {
// Put this here instead of having two lock/unlock blocks. We want
// to avoid a case where a client is removed from the temp users
// and added to the clients between the two blocks.
cr.clientsMtx.Unlock()
break
}
@ -347,7 +351,6 @@ func (cr *ChatRoom) Broadcast() {
}(conn, uuid)
}
}
cr.clientsMtx.Unlock()
case msg := <-cr.modqueue:
cr.clientsMtx.Lock()