Skip to content

Comments

fix(rematch): move game variable from module scope to function scope#1334

Merged
itsalaidbacklife merged 2 commits intomainfrom
fix/rematch-race-condition
Feb 13, 2026
Merged

fix(rematch): move game variable from module scope to function scope#1334
itsalaidbacklife merged 2 commits intomainfrom
fix/rematch-race-condition

Conversation

@seriouslysean
Copy link
Collaborator

@seriouslysean seriouslysean commented Feb 10, 2026

Found during a code audit for the gpu stuff. let game is declared at module scope in the rematch controller, meaning all concurrent requests share the same variable. If two players hit rematch at the same time, the second request overwrites game while the first is still using it.

Fix is just moving the declaration inside the function.

Issue number

  • N/A (found during code audit)

Please check the following

  • Do the tests still pass?
  • Is the code formatted properly?

Please describe additional details for testing this change

  1. npm run test:unit
  2. The race condition was hard to hit in practice, but this is a correctness fix — no behavior change for normal (non-concurrent) requests

Copilot AI review requested due to automatic review settings February 10, 2026 03:26
@seriouslysean seriouslysean added bug Something isn't working version-patch An update that warrants a bumping the project's patch version (e.g. 4.0.0 => 4.0.1) labels Feb 10, 2026
@seriouslysean seriouslysean self-assigned this Feb 10, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a concurrency/race condition in the rematch controller by ensuring request-specific game state is not shared across concurrent requests.

Changes:

  • Moved let game from module scope into the exported request handler scope to prevent cross-request state sharing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@itsalaidbacklife itsalaidbacklife added the backend Requires changes to the (node) backend webserver label Feb 13, 2026
@itsalaidbacklife itsalaidbacklife merged commit 6bb95e9 into main Feb 13, 2026
9 checks passed
@itsalaidbacklife itsalaidbacklife deleted the fix/rematch-race-condition branch February 13, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Requires changes to the (node) backend webserver bug Something isn't working version-patch An update that warrants a bumping the project's patch version (e.g. 4.0.0 => 4.0.1)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants