From ca5efad12c0aa4fdc6c6213fd3688a9f883dff2d Mon Sep 17 00:00:00 2001 From: Shwetas Dhake Date: Fri, 7 Aug 2026 14:55:14 +0530 Subject: [PATCH] Fix self-deadlock in handleRoleSelection --- backend/websocket/websocket.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/websocket/websocket.go b/backend/websocket/websocket.go index 589a6c5..b88f126 100644 --- a/backend/websocket/websocket.go +++ b/backend/websocket/websocket.go @@ -664,15 +664,17 @@ func handleTopicChange(room *Room, conn *websocket.Conn, message Message, roomID // handleRoleSelection handles role selection func handleRoleSelection(room *Room, conn *websocket.Conn, message Message, roomID string) { - // Store the role in the client + // Store the role in the client, releasing the lock before broadcasting + // since snapshotRecipients and broadcastParticipants lock room.Mutex themselves room.Mutex.Lock() - defer room.Mutex.Unlock() if client, exists := room.Clients[conn]; exists { if client.IsSpectator { + room.Mutex.Unlock() return } client.Role = message.Role } + room.Mutex.Unlock() // Broadcast role selection to other clients for _, r := range snapshotRecipients(room, conn) {