boardgame.io icon indicating copy to clipboard operation
boardgame.io copied to clipboard

Infinite loading screen with simultaneous match joins

Open Neodark7 opened this issue 2 years ago • 5 comments

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 ?

Neodark7 avatar Oct 07 '22 14:10 Neodark7

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.

vdfdev avatar Oct 08 '22 17:10 vdfdev

Basically, you need to serialize the requests in your client to avoid this isue

vdfdev avatar Oct 08 '22 17:10 vdfdev

@vdfdev what do you mean by "serializing the requests in your client" ?

Neodark7 avatar Oct 12 '22 13:10 Neodark7

Do them sequentially, not in parallel

vdfdev avatar Oct 12 '22 15:10 vdfdev

@vdfdev I don't see how i can do that since all players joins the game at the same time

Neodark7 avatar Oct 13 '22 12:10 Neodark7