summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhen <zhen00fa@gmail.com>2022-05-20 15:57:53 +0800
committerzhen <zhen00fa@gmail.com>2022-05-26 17:23:41 +0800
commit6b2216ebcce5f699b51d7d10b4100eef2dcbd5d0 (patch)
tree53b3ea2c18db1dd60c9f3b9c199d53dc3a05dba8
parentb21c20f79fbcf81b79706a5910ff802b405ca733 (diff)
downloadtooz-6b2216ebcce5f699b51d7d10b4100eef2dcbd5d0.tar.gz
Fix inappropriate logic in memcachedlock.release()
Whether 'was_deleted' was 'TRUE' or not, eventually we have to remove self from '_acquired_locks'. For example: 1. App #1 with coordinator 'A' wants to release lock "b" 2. 'self.coord.client.delete()' failed for some reason(.e.g, BrokenPipeError,MemcacheUnexpectedCloseError) 3. According to the former logic,lock "b" will not remove from "_acquired_locks", so "self.heartbeat()" will make it alive forever until App #1 was down or lock "b" turned expired. 4. Now App #1 with coordinator 'A' wants to acquire lock "c", who have the same lock-name with lock "b",It is clear that this will fail and prevent the locked program from continuing to execute. Change-Id: I6fc33b8e0a88510027bcfc30d1504489d2a91b4e
-rw-r--r--releasenotes/notes/memcached-fix-lock-release-I6fc33b8e0a88510.yaml4
-rw-r--r--tooz/drivers/memcached.py9
2 files changed, 11 insertions, 2 deletions
diff --git a/releasenotes/notes/memcached-fix-lock-release-I6fc33b8e0a88510.yaml b/releasenotes/notes/memcached-fix-lock-release-I6fc33b8e0a88510.yaml
new file mode 100644
index 0000000..aefd26c
--- /dev/null
+++ b/releasenotes/notes/memcached-fix-lock-release-I6fc33b8e0a88510.yaml
@@ -0,0 +1,4 @@
+---
+fixes:
+ - |
+ Fixs inappropriate logic in memcachedlock.release() \ No newline at end of file
diff --git a/tooz/drivers/memcached.py b/tooz/drivers/memcached.py
index 1cefd95..7cc40a9 100644
--- a/tooz/drivers/memcached.py
+++ b/tooz/drivers/memcached.py
@@ -150,11 +150,16 @@ class MemcachedLock(locking.Lock):
# it being done in the client side (non-atomic).
value = self.coord.client.get(self.name)
if value != self.coord._member_id:
+ # NOTE(zhen): Although ``member_ id`` is different, self lock
+ # object needs to be removed from'_ acquired_locks' because it
+ # has the same key.
+ self.coord._acquired_locks.remove(self)
return False
else:
+ # NOTE(zhen): Whether 'was_deleted' was 'TRUE' or not,
+ # eventually we have to remove self from '_acquired_locks'.
was_deleted = self.coord.client.delete(self.name, noreply=False)
- if was_deleted:
- self.coord._acquired_locks.remove(self)
+ self.coord._acquired_locks.remove(self)
return was_deleted
@_translate_failures