Fix lobby race: single-transaction gated add - #46
Open
wasita wants to merge 1 commit into
Open
Conversation
…action Previously reqMetaDocChange and checkIfResetCounter ran as two separate Firestore transactions. Between them the counter could grow past groupSize, and the === groupSize check would then fall through to a log-only branch, permanently deadlocking the lobby whenever 3+ users joined near-simultaneously. Collapse everything into one gated-add transaction that maintains the invariant counter.length < groupSize after every committed write. The closing user captures the dyad via the transaction's return value (not a closure variable, which would leak across retries) and calls initGroup; other users learn of the group via their participant-doc onSnapshot listener.
|
Visit the preview URL for this PR (updated for commit 78f2617): https://shared-reality-chat--pr46-fix-lobby-race-qbwlkh70.web.app (expires Tue, 14 Apr 2026 20:46:35 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 610727926b0a3107426ed7cfe5bfddf4ee1485a4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
How it works
Each `reqMetaDocChange` call runs one transaction that either:
Only the closed caller runs `initGroup`. Non-closing users are notified via the existing `onSnapshot` listener on their participant doc in `App.svelte:188`, which reactively subscribes them to the group doc once `initGroup` writes their `groupId` at `utils.js:1161`. (Listener chain verified in this PR.)
Test plan