Openvidu and backend server have different sessions state

From the site’s examples i understand that we manage user’s session log in (by giving sessions tokens) and session’s state (logged in users with their roles) with our backend using ConcurrentMaps.
Here is the problem.
I’m using the session name as a session id. I keep the connected users in a Map(session name, token). If this Map is empty then the session name is available. If the map is non-empty then a session is supposed to be running.
However, on the client side, a user can leave a session without sending a /remove-user request in order to update the map (for example when a user’s pc closes because of low battery). In this case, the openvidu server removes the user but the backend-spring boot server does not. So, the session name will never be available again. It will always look like the session is being used.

Does this problem have a solution?

You can use webhooks so your backend is notified about session changes.

You can also query to OpenVidu backend from time to time using the REST API to know the state of the sessions.