fix(p2p): deduplicate host initialization#6618
Conversation
|
Warning Review limit reached
Next review available in: 2 seconds Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughP2PHostAdapter initialization now runs once across concurrent and repeated calls, retries after failure, and has a regression test covering lobby-to-game handoff behavior. ChangesP2P host initialization
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@client/src/adapter/__tests__/p2p-adapter-multiplayer.test.ts`:
- Around line 410-418: Add a test alongside the existing host initialization
test that makes the first initialize attempt reject, verifies a subsequent
initialize succeeds, and then simulates a guest connection to assert it is
accepted exactly once. Exercise the retry through the adapter’s initialization
flow and verify failed initialization does not leave duplicate listeners or
otherwise prevent the successful retry.
In `@client/src/adapter/p2p-adapter.ts`:
- Around line 1105-1111: Make initialize and initializeInner retry-safe:
preserve single-flight behavior for concurrent callers, but reset or recreate
the constructor-owned pregameReady gate after a failed attempt so a later
successful retry can resolve it. Ensure each failed attempt removes its
onGuestConnected subscription before clearing initPromise and permitting another
retry, preventing duplicate guest processing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 1bb96475-8d61-4d3d-926f-32f8614c6295
📒 Files selected for processing (2)
client/src/adapter/__tests__/p2p-adapter-multiplayer.test.tsclient/src/adapter/p2p-adapter.ts
Summary by CodeRabbit