cuttle-cards / cuttle

A two-player battle card game for all ages, built with nodejs, sailsjs, and vuejs
MIT License
136 stars 103 forks source link

[Bug]: Three players joining a game simultaneously can cause all three to join #785

Open itsalaidbacklife opened 10 months ago

itsalaidbacklife commented 10 months ago

Bug Summary

A race condition in requests to join a game can cause too many players to join the game because the game doesn't appear full at the time the multiple requests to join are processed. We should fix this by utilizing the new lock-game helper in the subscribe game endpoint.

Detailed Description

783 introduced the lock-game and unlock-game helpers which the backend can use to force requests dealing with a particular game are processed in sequence, rather than in parallel. #783 applies these helpers to the ready.js api endpoint in order to prevent race conditions in requests to ready/unready for a game. We should apply the same locking/unlocking the game techniques in api/controllers/game/subscribe.js to prevent a similar race condition in the subscribe action.

Current Behavior

Multiple players joining a game simultaneously sometimes causes all of them to 'successfully' join, resulting in more than 2 players in the game.

Expected Behavior

Only two players should be able to join a game at a time.

Steps to Reproduce

  1. Sign in with three accounts in three windows
  2. Create a game
  3. Join it as one player
  4. Hit the join button with the two other players at the same time. They might both be admitted into the game, resulting in 3 total players in the game, instead of 2.
fuveluck commented 8 months ago

I`ll take it :)