Need advice on solution about socket/session for Stream

Hi,

I’m using Stream to get current online user. When user is authenticated, client will join stream by its session. 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”.

So I changed process a bit on join/leave Stream. When session is expired, client will disconnect first and then re-authenticate. I would like to ask for your advice.
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?

Thanks.

@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.

https://heroiclabs.com/docs/install-configuration/#session

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.

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”?

The session expiry is default 60s so that it will expire quickly. The problem is session is expired but socket doesn’t close at the moment. And we are trying to solve the problem by disconnect and re-authenticate from client-side.

Thank you for quick response!