1. cherrypy
  2. CherryPy
  3. Pull requests

Pull requests

#50 Merged at 9389d1f
Repository
shroom
Branch
default
Repository
cherrypy
Branch
default

Fix race condition in session clean up.

Author
  1. Mateusz Pachocki
Reviewers
Description

The lifecycle of a request consists of:

  1. Check if session id was already registered. If not, create a new session id.

  2. Load data and acquire lock.

  3. Save data and release lock. Update the cache.

  4. Close session.

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:

ERROR:cherrypy.error.53862032:[21/Aug/2013:11:41:03]  Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 102, in run
    hook()
  File "/usr/local/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 62, in __call__
    return self.callback(**self.kwargs)
  File "/usr/local/lib/python2.7/dist-packages/cherrypy/lib/sessions.py", line 698, in save
    cherrypy.session.save()
  File "/usr/local/lib/python2.7/dist-packages/cherrypy/lib/sessions.py", line 230, in save
    self.release_lock()
  File "/usr/local/lib/python2.7/dist-packages/cherrypy/lib/sessions.py", line 374, in release_lock
    self.locks[self.id].release()
KeyError: u'2153491baec96c27bed90ecea71c2295b5a955bd'

The fix checks whether it's possible to acquire given lock. If so, the lock id is removed, if not, nothing happens, request's thread will take care of that lock.

Comments (1)

  1. Alex Latchford

    Hey all,

    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.

    Cheers, Alex