Add NoNodeError handlers in ZK locks
Instead of looping 5+ times acquiring an impossible lock on a nonexistent key, just fail on a different error and return failure immediately. This is likely a major corner case that shouldn't happen, but better to be safe than 500.
This commit is contained in:
parent
a080598781
commit
e093efceb1
|
@ -364,6 +364,9 @@ class ZKHandler(object):
|
|||
lock_id = str(uuid.uuid1())
|
||||
lock = self.zk_conn.ReadLock(path, lock_id)
|
||||
break
|
||||
except NoNodeError:
|
||||
self.log("ZKHandler warning: Failed to acquire read lock on nonexistent path {}".format(path), state='e')
|
||||
return None
|
||||
except Exception as e:
|
||||
if count > 5:
|
||||
self.log("ZKHandler warning: Failed to acquire read lock after 5 tries: {}".format(e), state='e')
|
||||
|
@ -389,6 +392,9 @@ class ZKHandler(object):
|
|||
lock_id = str(uuid.uuid1())
|
||||
lock = self.zk_conn.WriteLock(path, lock_id)
|
||||
break
|
||||
except NoNodeError:
|
||||
self.log("ZKHandler warning: Failed to acquire write lock on nonexistent path {}".format(path), state='e')
|
||||
return None
|
||||
except Exception as e:
|
||||
if count > 5:
|
||||
self.log("ZKHandler warning: Failed to acquire write lock after 5 tries: {}".format(e), state='e')
|
||||
|
@ -414,6 +420,9 @@ class ZKHandler(object):
|
|||
lock_id = str(uuid.uuid1())
|
||||
lock = self.zk_conn.Lock(path, lock_id)
|
||||
break
|
||||
except NoNodeError:
|
||||
self.log("ZKHandler warning: Failed to acquire exclusive lock on nonexistent path {}".format(path), state='e')
|
||||
return None
|
||||
except Exception as e:
|
||||
if count > 5:
|
||||
self.log("ZKHandler warning: Failed to acquire exclusive lock after 5 tries: {}".format(e), state='e')
|
||||
|
|
Loading…
Reference in New Issue