boardgame.io
boardgame.io copied to clipboard
Infinite loading screen with simultaneous match joins
Hi ! i have a custom lobby mechanism on my project which implement basic matchmaking between players. When sufficient players have joined the lobby i create the match from my api and send an event to all the players to redirect them to the match page. When the match page load, an http call occurs to log the user to the game server.
It seems that the boardgame implementation cannot handle simultaneous connection changes properly. When someone logs into the match (https://github.com/boardgameio/boardgame.io/blob/main/src/master/master.ts#L400) the match metadata is fetched from my database, modified to include the new metadata, sent to all clients and then saved to the database.
When 2 players joins the match simultaneously, this logic is called 4 times simultaneously and it looks like that some players are overriding the metadata changes of previous users.
For example:
Player 1 is redirected to match page Player 2 is redirected to match page
Player 1 onConnectionChange method start and fetch metadata Player 2 onConnectionChange method start and fetch metadata
Player 1 onConnectionChange method modify metadata and save it to the database Player 2 onConnectionChange method modify metadata and save it to the database
as Player 2 fetched the metadata before Player 1 finished modifying and saving it to the database, when Player 2 modify and save the metadata into the database, the data is outdated and does not contain Player 1 isConnected and credentials values. Player 2 is correctly logged into the match but Player 1 stay on the "Connecting..." screen indefinitely and the match get stuck when his turn start...
Sometimes everything plays nicely in the correct order but most of the time, for example in a 4 players match, a player stay on the loading screen and the match is blocked, this is really critical for my project, how can this be fixed ?
Yep, this is a known issue: https://github.com/boardgameio/boardgame.io/issues/429 our lobby lacks transactions and concurrency controls. Any contribution to help with that would be appreciated.
Basically, you need to serialize the requests in your client to avoid this isue
@vdfdev what do you mean by "serializing the requests in your client" ?
Do them sequentially, not in parallel
@vdfdev I don't see how i can do that since all players joins the game at the same time