Spectator mode: 504 Gateway Time-out

Game development with Board Game Arena Studio
Post Reply
User avatar
myriam9456
Posts: 9
Joined: 04 January 2021, 01:27

Spectator mode: 504 Gateway Time-out

Post by myriam9456 »

Hi!

I developed Hoarders, my first game, that reached Beta today. I have issues with the spectator mode. Whenever I try to spectate a game (whether in studio or in production), the request gets timed-out and I receive a 504 Gateway Time-out response. Here is the log linked to that event during the game (I don't know if it can be of any help!):

Code: Select all

06/03 01:40:01 [info] [M] [2344221/SpectatorUsername] /1/hoarders?table=2430680
06/03 01:40:02 [info] [T243068] [2344221/SpectatorUsername] 1.3768672943115 SELECT global_id, global_value FROM global WHERE 1 0
06/03 01:40:02 [info] [T243068] [2344221/SpectatorUsername] setTable0
06/03 01:40:02 [info] [T243068] [2344221/SpectatorUsername] 1.3070106506348 SELECT global_id, global_value FROM global WHERE 1 0
06/03 01:40:02 [info] [T243068] [2344221/SpectatorUsername] Complete reinitialization of board game0
06/03 01:40:02 [info] [T243068] [2344221/SpectatorUsername] DB commit: action validate0
06/03 01:40:02 [info] [T243068] [2344221/SpectatorUsername] Generate content of game view0
06/03 01:40:02 [info] [T243068] [2344221/SpectatorUsername] setTable0
06/03 01:40:02 [info] [T243068] [2344221/SpectatorUsername] 1.2760162353516 SELECT global_id, global_value FROM global WHERE 1 0
During development, I completely ignored the spectator mode (there isn't any logic or special path for that mode anywhere) so the issue is probably coming from there.

Do you have to do anything for the spectator mode to work?

Thank you!
User avatar
paramesis
Posts: 398
Joined: 28 April 2020, 05:00

Re: Spectator mode: 504 Gateway Time-out

Post by paramesis »

Generally you do have to add some logic to accommodate spectators both on the server side and interface side. This is often overlooked in Alpha projects.

On the server side, a spectator's current player id retrieved from self::getCurrentPlayerId() will not exist in the player table.
Since it was public, I went ahead and took a peek at your project. It looks like there would be an error triggered by line 157 of your game.php, where you index into an array returned by a sql query with a key that doesn't exist if you're a spectator:

Code: Select all

$result['actions'] = self::getCollectionFromDb( $sql )[$current_player_id];
You could replace this with:

Code: Select all

$actions_temp = self::getCollectionFromDb( $sql );
if( array_key_exists( $current_player_id, $actions_temp ) ) {
  $result['actions'] = $actions_temp[$current_player_id];
}
On the client side, you'll want to make sure the setup can handle the $result['actions'] being undefined, and to verify that this.player_id is not being used in a context where members of gamedatas or DOM elements are expected to exist. This is the most common error I see. You can address both by checking the this.isSpectator flag
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Spectator mode: 504 Gateway Time-out

Post by Een »

I checked it as this kind of thing might cause performance issues.

The error is :
PHP Fatal error: Maximum execution time of 300 seconds exceeded in hoarders/210306-0720/hoarders.view.php on line 52

So it would seem that in the case of spectator you have an infinite loop or something like that.
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Spectator mode: 504 Gateway Time-out

Post by Een »

I patched your view.php with a comment and redeployed to solve the error in production (we have added to our checklist to check the spectator mode before pushing a game to beta, the game should not have been deployed to beta with this issue).

You will still have to make some extra checks as indicated by paramesis to make the spectator mode fully functional (currently there is a javascript error message).
User avatar
myriam9456
Posts: 9
Joined: 04 January 2021, 01:27

Re: Spectator mode: 504 Gateway Time-out

Post by myriam9456 »

Thank you both for your help/explanation! I'll look into it and fix the other errors.

Een, could you make sure to add something, somewhere in the doc about how to handle spectator mode. I feel this is a relevant part of the development and I wasn't able to find any information in the doc to help me solve my problem (there is some mention of this.isSpectator for the client side but nothing about the server side (which is where my problem was coming from)).

Thank you again!
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Spectator mode: 504 Gateway Time-out

Post by Een »

myriam9456 wrote: 08 March 2021, 15:33 Een, could you make sure to add something, somewhere in the doc about how to handle spectator mode. I feel this is a relevant part of the development and I wasn't able to find any information in the doc to help me solve my problem (there is some mention of this.isSpectator for the client side but nothing about the server side (which is where my problem was coming from)).
Actually, we didn't have a isSpectator method on the server side, we let the developers check themselves if the user accessing the game was among the player list, which was indeed not obvious.
I have added this method in the framework (NB: I have added it to the documentation, but it will become available only with the next site release).
Post Reply

Return to “Developers”