From a333c7906621ebd609fa2c56d6ca1691f47eba04 Mon Sep 17 00:00:00 2001 From: Imran Ansari Date: Fri, 28 Jul 2017 21:09:02 +0000 Subject: [PATCH] Acquire fails with "ToozError: Not found" For Etcd3Lock, blocking call to acquire an already acquired lock fails when the thread/process, that acquired the lock takes more than the timeout specified for the lock. Scenario ======== 1. First thread acquires a lock "Lock1" 2. Second thread tries to acquire "Lock1" with blocking=True 3. First thread releases lock after few minutes 4. Second thread tries to acquire it and fails with exception: ToozError: Not found Cause ===== Lease gets created when the lock is created and the default timeout is 30 secs. Since the first thread takes more than 30 seconds to complete, the lease for the second thread gets expired leading to "Not found" message. Resolution ========== Create lease within Etcd3Lock.acquire() rather than Etcd3Lock.__init__() of Etcd3Lock Change-Id: Ief75675ebde2d824a25aec6210e2a868cf3dbbe7 Closes-Bug: #1708836 --- tooz/drivers/etcd3gw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooz/drivers/etcd3gw.py b/tooz/drivers/etcd3gw.py index c3367ca4..d2a7781c 100644 --- a/tooz/drivers/etcd3gw.py +++ b/tooz/drivers/etcd3gw.py @@ -68,7 +68,6 @@ class Etcd3Lock(locking.Lock): self._key = self.LOCK_PREFIX + name self._key_b64 = base64.b64encode(self._key).decode("ascii") self._uuid = base64.b64encode(uuid.uuid4().bytes).decode("ascii") - self._lease = self._coord.client.lease(self._timeout) self._exclusive_access = threading.Lock() @_translate_failures @@ -80,6 +79,7 @@ class Etcd3Lock(locking.Lock): def _acquire(): # TODO(jd): save the created revision so we can check it later to # make sure we still have the lock + self._lease = self._coord.client.lease(self._timeout) txn = { 'compare': [{ 'key': self._key_b64,