Skip to content

Fix self-deadlock in handleRoleSelection - #396

Open
shwetd19 wants to merge 1 commit into
AOSSIE-Org:mainfrom
shwetd19:fix/role-selection-deadlock
Open

Fix self-deadlock in handleRoleSelection#396
shwetd19 wants to merge 1 commit into
AOSSIE-Org:mainfrom
shwetd19:fix/role-selection-deadlock

Conversation

@shwetd19

@shwetd19 shwetd19 commented Aug 7, 2026

Copy link
Copy Markdown

Fixes #391

handleRoleSelection held room.Mutex (via defer) while calling snapshotRecipients and broadcastParticipants, which both re-lock the same non-reentrant mutex, deadlocking the connection's read loop on every role pick. The lock is now released before broadcasting.

Summary by CodeRabbit

  • Bug Fixes
    • Improved room responsiveness during role selection by preventing unnecessary delays in participant and recipient updates.
    • Preserved existing role assignment behavior for players and spectators.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 78cf49f4-50f4-4669-96e6-867ce00dc8a9

📥 Commits

Reviewing files that changed from the base of the PR and between 51532ff and ca5efad.

📒 Files selected for processing (1)
  • backend/websocket/websocket.go

📝 Walkthrough

Walkthrough

handleRoleSelection now explicitly unlocks room.Mutex before spectator returns and before recipient or participant broadcasts. This prevents the broadcast helpers from attempting to reacquire the same mutex.

Changes

Role selection deadlock fix

Layer / File(s) Summary
Unlock before role broadcasts
backend/websocket/websocket.go
handleRoleSelection uses explicit mutex unlocks before returning for spectators and before broadcasting role and participant updates.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: priyanshunitr

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary fix: preventing the self-deadlock in handleRoleSelection.
Linked Issues check ✅ Passed The change releases room.Mutex before helper calls, preventing recursive locking and restoring role selection and message delivery required by issue #391.
Out of Scope Changes check ✅ Passed The changes are limited to unlocking room.Mutex in handleRoleSelection and are directly related to issue #391.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gitcordapp

gitcordapp Bot commented Aug 7, 2026

Copy link
Copy Markdown

Link your account with Gitcord

Thanks for opening this PR, @shwetd19!

To receive Discord notifications and contributor tracking for this organization:

  1. Join Discord: https://discord.gg/hjUhu33uAn
  2. In Discord, run /link shwetd19
  3. Paste the verification code into your GitHub bio (or a public gist)
  4. Click Verify in Discord (or run /verify-link shwetd19)

Once linked, Gitcord can notify you about reviews, merges, and more.

Posted by Gitcord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Self-deadlock in handleRoleSelection hangs the WebSocket connection on every role pick

1 participant