Join GitHub today
session.DiskStore concurrency issue #191
When hammering web.py with a huge amount of requests whereby each request updates the session, exceptions will be thrown. (Usually during the decode of the pickle string from the disk but other exceptions are possible)
We believe that if one thread is writing the session info, that a second thread that reads/writes to the same session simultaneously will cause an uncaught exception.
A possible solution is to update session.DiskStore.setitem to become:
def __setitem__(self, key, value): path = self._get_path(key) pickled = self.encode(value) try: tname = path+"."+threading.current_thread().getName() f = open(tname, 'w') try: f.write(pickled) finally: f.close() os.rename(tname, path) # atomary operation except IOError: pass
This comment has been minimized.
This comment has been minimized.Show comment Hide comment
May I suggest to create a pull request this change?
Soon or later one of the project maintainers will decide to consider this (or not) the best solution for the problem, and having a pull request to analyze will surely increase the odds of having this fix merged into the main branch.