session.DiskStore concurrency issue #191

Open
HansWeltar opened this Issue Nov 20, 2012 · 5 comments

Comments

Projects
None yet
4 participants
@HansWeltar

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
@HansWeltar

This comment has been minimized.

Show comment Hide comment
@HansWeltar

HansWeltar Nov 24, 2012

Seems a duplicate of issue 182

Seems a duplicate of issue 182

@eduardohenriquearnold

This comment has been minimized.

Show comment Hide comment
@eduardohenriquearnold

eduardohenriquearnold Apr 10, 2013

Same as issue #83

Same as issue #83

@eduardohenriquearnold

This comment has been minimized.

Show comment Hide comment
@eduardohenriquearnold

eduardohenriquearnold Apr 10, 2013

This seems to fix any error this issue may be causing. How do we mark this issue as closed? And how do we suggest this to be applied in the new web.py release?

This seems to fix any error this issue may be causing. How do we mark this issue as closed? And how do we suggest this to be applied in the new web.py release?

@iamFIREcracker

This comment has been minimized.

Show comment Hide comment
@iamFIREcracker

iamFIREcracker Apr 10, 2013

Contributor

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.

Contributor

iamFIREcracker commented Apr 10, 2013

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.

@giter

This comment has been minimized.

Show comment Hide comment
@giter

giter Aug 29, 2014

Yes seems fix my problem!

giter commented Aug 29, 2014

Yes seems fix my problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment