Invalid session workaround

In my setup I was noticing a strange communication problem in my GenieACS setup. Sometimes, randomly during an inform a GenieACS would raise an “Invalid Session” error.

2022-05-25T16:24:55.095Z [ERROR] ::ffff:1.2.3.4: Invalid session

Digging in the source code I was able to determine this error was happening because GenieACS were unable to recover a session from mongo’s cache. To be more precise, this “cache.pop” function call was returning null when it should be returning the active session.

image

When I manually looked at the database, I was surprised that there was an entry with the correspondent session_id there, and that function should not be returning null…

This should mean there was a race condition where cache.pop was being called before cache.set could put back the session in the database. Looking at the source again, I found that cache.set is called (for sessions) only when the socket closes, so this means the CPE was initiating a new connection before the previous one closed (on the server side, at least).

To mitigate this problem I edited cache.pop function to add a “second try” query in the cache in case the socket hasn’t finished closing.

image

This seems to have worked, now I have absolutely zero invalid session errors in my setup.

1 Like

I was having a similar issue and tried this. Seems to work, but seems kinda hacky. Wonder if there would be a better way to handle this?

I have not found this yet. I added this change in my fork of genieacs on github so I don’t lose this modifications when I compile my docker image. Something I noticed later is that the devs implemented this timeout before each cache.pop call, suggesting they must have faced a similar problem in some capacity.