Changeset - efce61aac33d
[Not reviewed]
stable
0 1 0
Mads Kiilerich - 10 years ago 2015-12-25 12:37:49
madski@unity3d.com
db: handle race when multiple threads add the same cache invalidation entry simultaneously (Issue #177)
1 file changed with 7 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/model/db.py
Show inline comments
 
@@ -2142,7 +2142,13 @@ class CacheInvalidation(Base, BaseModel)
 
            return True
 
        inv_obj.cache_active = True
 
        Session().add(inv_obj)
 
        Session().commit()
 
        try:
 
            Session().commit()
 
        except exc.IntegrityError:
 
            inv_obj = cls.query().filter(cls.cache_key == cache_key).scalar()
 
            if not inv_obj:
 
                raise
 
            # TOCTOU - another thread added the key at the same time; no further action required
 
        return False
 

	
 
    @classmethod
0 comments (0 inline, 0 general)