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