From e093efceb1c449dba285777c501696c715d24d44 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Thu, 1 Jul 2021 01:17:38 -0400 Subject: [PATCH] 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. --- daemon-common/zkhandler.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/daemon-common/zkhandler.py b/daemon-common/zkhandler.py index b3c942ee..77343e0a 100644 --- a/daemon-common/zkhandler.py +++ b/daemon-common/zkhandler.py @@ -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')