Mercurial > kallithea
changeset 5607:efce61aac33d stable
db: handle race when multiple threads add the same cache invalidation entry simultaneously (Issue #177)
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Fri, 25 Dec 2015 12:37:49 +0100 |
parents | 2bf5e8731154 |
children | 9a4d4e623c85 2189802db18a |
files | kallithea/model/db.py |
diffstat | 1 files changed, 7 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/model/db.py Fri Dec 25 12:33:13 2015 +0100 +++ b/kallithea/model/db.py Fri Dec 25 12:37:49 2015 +0100 @@ -2142,7 +2142,13 @@ 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