Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate move on game #226

Open
benjaminpjones opened this issue Mar 30, 2024 · 1 comment
Open

Duplicate move on game #226

benjaminpjones opened this issue Mar 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@benjaminpjones
Copy link
Collaborator

benjaminpjones commented Mar 30, 2024

This game got broken by a duplicate move: https://www.govariants.com/game/65cf8f1ee7d31b1d396fe3c7

@benjaminpjones
Copy link
Collaborator Author

benjaminpjones commented Mar 30, 2024

The race could look something like this:

  1. User POSTs game/xxx/move twice
    • Not sure how this happens, but server should be prepared for anything
  2. Call 1 pulls the game from the database
  3. Call 2 pulls the game from the database
  4. Call 1 pushes the move onto the end of the array (See updateOne)
  5. Call 2 pushes the move onto the end of the array

A couple solutions I can think of:

  • place a “pending” field on the game document using findAndModify, return early if the object is already being edited
    • (This one seems really easy to screw up)
  • Replace the array ($set) rather than just pushing ($push) the last move, so we always have a valid moves array
  • We could add some self-healing, so if the db gets corrupted like this, we just remove the bad moves when the game is requested
    • This could be done in conjunction with fixing the race condition

@benjaminpjones benjaminpjones added the bug Something isn't working label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant