How to deal with terminating game sessions with zero players in them


Hello everyone, I am a bit stuck on how I should deal with cleaning up active game sessions with zero players in them. Before, I implemented game logic that would terminate a game session and end the server process if no players were in the game after a certain amount of time. Besides the obvious fact that it isn't necessarily good to constantly restart the server process, I realized that this created a few race conditions.

  1. Players joining the game right before the server process exits. This occurs when players find a match and it takes a certain amount of time to join the game so that by the time they join, the timer function that checks for any players already got called, but the call to terminating the game session and ending the server process has not quite been reached yet.

  2. Players join the game during the ending/termination of the server process/game session. Personally, I am still not sure if this can even happen, and even if it does, I think joining the server will end up taking so long that the client will ultimately join the restarted server process. I think in this case I should just kick the player out. Also, I am wondering if this may interfere with FlexMatch, if possible, because I did get a ticket with this error message, The game session null was not found, or was in a state which wouldn't accept new player sessions. and was wondering if this scenario could have caused it.

  3. Players join the game by the time the server process restarts. This case can be caused if the players got matched with a game session, but they took so long to join that the timer function that checks for any players already got called and thereby called the logic that terminates/ends the game session/server process. This tends to happen quite often, and I believe kicking the player out of the server is the best way to deal with this.

I have briefly looked into auto-scaling fleets with rule-based policies, but I am unsure if I will end up coming across the same race conditions outlined above. Especially since I have come across these forum posts that don't seem to have a concrete answer:

Also, would it be possible to get a sample policy that scales down game sessions with no players? Thing is I want to be careful again, because I know clients joining the server takes time. That is why I mentioned the race conditions above. I know setting fleets to have full protection will protect game sessions with players. Does this mean game sessions with reserved and active player sessions are protected, or just game sessions with active player sessions? Lastly, I believe player sessions time out after 1 minute if they are not accepted within this time frame so perhaps these pieces of information may come in helpful for dealing with this. I know this was a lot, so thanks in advance.

asked 4 years ago241 views
1 Answer
Accepted Answer

One thing to bear in mind that if you are using PlayerSessions, players have 60s to join. After that their session has timed out and AcceptPlayerSession will fail (which can be useful when using FlexMatch).

  1. You just need a long enough timer for players to get into the server ie 2 x player session length.

  2. This is much more todo with the length of your game sessions, your management of backfill tickets and your game mode. Does it make sense for players to arrive this late in the game? When should you stop manual/automatic backfill and also remember to terminate the backfill tickets in flight long before your game ends / at game end.

  3. Player arriving on stale player sessions should be rejected. Server would have new game session id etc.

Really its more about following good software development thread safe patterns to handle async events relating to player connections

  • It also sounds like you may not be cancelling backfill tickets issued by your server.

Right now GameLift only supports target tracking on unused gamesessions. A GameSession with no players is considered 'in use' so you need to make the decision to when to terminate from the server process itself.

Hopefully that makes sense.

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions