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
This commit is contained in:
parent
1b321bcfc1
commit
a333c79066
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue