Stale values mapSessions blocks users in openvidu-js-node

I have an application based on the openvidu-js-node tutorial, and I’m having trouble with phantom sessions getting stuck in the mapSession object.

Essentially, if users logout unexpectedly (say, closing their browser window), the node backend doesn’t always detect this. OpenVidu will eventually kill off the dead session, but within the openvidu-js-node backend, it keeps an entry in the mapSessions array.

As a result, the next time someone tries to join SessionA, the application receives a 404, because the OpenVidu session no longer exists, even though the node backend thinks it exists.

Currently the only logic that will delete a session in the node backend is if the tokens == 0:

 if (tokens.length == 0) {
                // Last user left: session must be removed
                console.log(sessionName + ' empty!');
                delete mapSessions[sessionName];
            }

However, if the last user in the session closes abruptly, there’s not necessarily a call to /sessions/remove-user to run this code.

Any suggestions on keeping the state of node’s session list in sync with the OpenVidu sessions?

I’ve currently tried deleting a session from the mapSessions if it returns an error, but that seems to be causing connections issues with valid sessions as well.

I’m experimenting with using OV.fetch() to check sessions every few seconds and purge my local sessions, but this seems pretty sketchy and open to more bugs.

Any insights would be much appreciated!

You can try to subscribe to webhook

https://docs.openvidu.io/en/2.18.0/reference-docs/openvidu-server-cdr/#sessiondestroyed

So you are notified when a session is destroyed in OpenVidu and you can remove it from mapSessions in Node.

Regards

1 Like