Check if session id was already registered. If not, create a new session id.
Load data and acquire lock.
Save data and release lock. Update the cache.
If clean up happens between steps two and three, the session id will be in the locks dict, but not in the cache dict, therefore clean up will remove lock id from the dict and when request's thread tries to release the lock, it will raise an exception:
I'm getting hit by this problem at the moment is there any reason this pull request isn't being merged? I can pick up where Mateusz Pachocki left off if work needs to be done on it, it looks good too my untrained eye at the moment.