@renhades What value do you set your
token_expiry_sec value in the server? We recommend its set to at least 2-3 times the expected average play session for players in your game. If you’re unsure a good value can also be 1 day or even slightly longer.
And I encountered a scenario, client will check session is expired and authenticate again. That will cause online user count keep +1 even now there is only 1 user online. Server-side won’t let user leave Stream because server doesn’t get “connection closed”.
This isn’t clear to me. When a socket connection is closed client-side or server-side it will always be cleaned up from any streams automatically. What do you mean “server-side won’t let user leave”?
Is my solution on update/get online user stream reasonable? And is it bad if frequently closed connection or there is a better solution on update online user by Stream?
This should be a rare scenario to deal with because an active session that has expired while still active on the socket can be avoided with a check at game startup to see if the time left on the token before it expires is less than 6 hours or some value and reauthenticate ahead of the time the token expires.
In any case there’s no problem with sending a disconnect for the client on the socket and then doing a reconnect. The server will have no problem at all with it. Any mobile game will see events which cause disconnect and reconnects to happen all the time just due to the unreliable network conditions with most cellular carriers.