# Stale values mapSessions blocks users in openvidu-js-node

**URL:** <https://openvidu.discourse.group/t/stale-values-mapsessions-blocks-users-in-openvidu-js-node/3152>\
**Category:** Issues developing apps\
**Tags:** v2\
**Created:** [June 18, 2021, 3:03am UTC](https://openvidu.discourse.group/t/stale-values-mapsessions-blocks-users-in-openvidu-js-node/3152 "2021-06-18T03:03:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jolephoto](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/jolephoto/32/904_2.png) [@jolephoto](https://openvidu.discourse.group/u/jolephoto)\
**Post date:** [June 18, 2021, 3:03am UTC](https://openvidu.discourse.group/t/stale-values-mapsessions-blocks-users-in-openvidu-js-node/3152/1 "2021-06-18T03:03:34Z")

</div>

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:

```auto
 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!

---

<div class="post-metadata">

**Author:** ![micael.gallego](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/micael.gallego/32/2_2.png) [@micael.gallego](https://openvidu.discourse.group/u/micael.gallego)\
**Post date:** [June 18, 2021, 7:44am UTC](https://openvidu.discourse.group/t/stale-values-mapsessions-blocks-users-in-openvidu-js-node/3152/2 "2021-06-18T07:44:03Z")

</div>

You can try to subscribe to webhook

[https://docs.openvidu.io/en/2.18.0/reference-docs/openvidu-server-cdr/#sessiondestroyed](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
