Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1924

Show
Ignore:
Timestamp:
03/16/08 10:33:19
Author:
fumanchu
Message:

Fix for #799 (_test_concurrency fails periodically). Turns out the anti-malicious-session-id stuff was returning None in some cases because it didn't use the lock file. Fixed by making init use os.path.exists (etc) instead of session._load.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/lib/sessions.py

    r1922 r1924  
    7474        else: 
    7575            self.id = id 
    76             if self._load() is None
     76            if not self._exists()
    7777                # Expired or malicious session. Make a new one. 
    7878                # See http://www.cherrypy.org/ticket/709. 
     
    9393            self.id = self.generate_id() 
    9494            # Assert that the generated id is not already stored. 
    95             if self._load() is not None
     95            if self._exists()
    9696                self.id = None 
    9797         
     
    245245                    pass 
    246246     
     247    def _exists(self): 
     248        return self.id in self.cache 
     249     
    247250    def _load(self): 
    248251        return self.cache.get(self.id) 
     
    270273 
    271274class FileSession(Session): 
    272     """ Implementation of the File backend for sessions 
     275    """Implementation of the File backend for sessions 
    273276     
    274277    storage_path: the folder where session data will be saved. Each session 
     
    309312            raise cherrypy.HTTPError(400, "Invalid session id in cookie.") 
    310313        return f 
     314     
     315    def _exists(self): 
     316        path = self._get_file_path() 
     317        return os.path.exists(path) 
    311318     
    312319    def _load(self, path=None): 
     
    420427        self.db.commit() 
    421428     
     429    def _exists(self): 
     430        # Select session data from table 
     431        self.cursor.execute('select data, expiration_time from session ' 
     432                            'where id=%s', (self.id,)) 
     433        rows = self.cursor.fetchall() 
     434        return bool(rows) 
     435     
    422436    def _load(self): 
    423437        # Select session data from table 
     
    484498        cls.cache = memcache.Client(cls.servers) 
    485499    setup = classmethod(setup) 
     500     
     501    def _exists(self): 
     502        self.mc_lock.acquire() 
     503        try: 
     504            return bool(self.cache.get(self.id)) 
     505        finally: 
     506            self.mc_lock.release() 
    486507     
    487508    def _load(self): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets