From d1c5d785c88586d4960868eb9cabd0032fac8e81 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Tue, 12 Jul 2022 10:09:22 +0200 Subject: [PATCH] Fix deadlock if virtual session leaves room. --- room.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/room.go b/room.go index fbcaf7f..6a74653 100644 --- a/room.go +++ b/room.go @@ -452,8 +452,6 @@ func (r *Room) RemoveSession(session Session) bool { return true } - // Still need to publish an event so sessions on other servers get notified. - r.PublishSessionLeft(session) r.hub.removeRoom(r) r.statsRoomSessionsCurrent.Delete(prometheus.Labels{"clienttype": HelloClientTypeClient}) r.statsRoomSessionsCurrent.Delete(prometheus.Labels{"clienttype": HelloClientTypeInternal}) @@ -461,6 +459,8 @@ func (r *Room) RemoveSession(session Session) bool { r.unsubscribeBackend() r.doClose() r.mu.Unlock() + // Still need to publish an event so sessions on other servers get notified. + r.PublishSessionLeft(session) return false } @@ -564,6 +564,7 @@ func (r *Room) PublishSessionLeft(session Session) { func (r *Room) addInternalSessions(users []map[string]interface{}) []map[string]interface{} { now := time.Now().Unix() r.mu.Lock() + defer r.mu.Unlock() for _, user := range users { sessionid, found := user["sessionId"] if !found || sessionid == "" { @@ -592,7 +593,6 @@ func (r *Room) addInternalSessions(users []map[string]interface{}) []map[string] "virtual": true, }) } - r.mu.Unlock() return users }