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:
Joshua Boniface 2021-07-01 01:17:38 -04:00
parent a080598781
commit e093efceb1
1 changed files with 9 additions and 0 deletions

View File

@ -364,6 +364,9 @@ class ZKHandler(object):
lock_id = str(uuid.uuid1()) lock_id = str(uuid.uuid1())
lock = self.zk_conn.ReadLock(path, lock_id) lock = self.zk_conn.ReadLock(path, lock_id)
break 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: except Exception as e:
if count > 5: if count > 5:
self.log("ZKHandler warning: Failed to acquire read lock after 5 tries: {}".format(e), state='e') 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_id = str(uuid.uuid1())
lock = self.zk_conn.WriteLock(path, lock_id) lock = self.zk_conn.WriteLock(path, lock_id)
break 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: except Exception as e:
if count > 5: if count > 5:
self.log("ZKHandler warning: Failed to acquire write lock after 5 tries: {}".format(e), state='e') 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_id = str(uuid.uuid1())
lock = self.zk_conn.Lock(path, lock_id) lock = self.zk_conn.Lock(path, lock_id)
break 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: except Exception as e:
if count > 5: if count > 5:
self.log("ZKHandler warning: Failed to acquire exclusive lock after 5 tries: {}".format(e), state='e') self.log("ZKHandler warning: Failed to acquire exclusive lock after 5 tries: {}".format(e), state='e')