From 1a06b55151d689555202d0883017f9b4a5ed20a0 Mon Sep 17 00:00:00 2001 From: zzz <41989224+zengzhuozhen@users.noreply.github.com> Date: Mon, 30 Jan 2023 13:29:38 +0800 Subject: [PATCH] fix:RLock twice when broadcast.Rooms(nil) (#562) * fix:RLock twice when broadcast.Rooms(nil) --------- Co-authored-by: zengzz01 --- broadcast.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/broadcast.go b/broadcast.go index 5a956efd..8d4b71c6 100644 --- a/broadcast.go +++ b/broadcast.go @@ -131,13 +131,13 @@ func (bc *broadcast) Len(room string) int { // no connection is given, in case of a connection is given, it gives // list of all the rooms the connection is joined to func (bc *broadcast) Rooms(connection Conn) []string { - bc.lock.RLock() - defer bc.lock.RUnlock() - if connection == nil { return bc.AllRooms() } + bc.lock.RLock() + defer bc.lock.RUnlock() + return bc.getRoomsByConn(connection) }