Skip to content

recipe(lock): retry lock cleanup #760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions kazoo/recipe/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ def acquire(self, blocking=True, timeout=None, ephemeral=True):
except KazooException:
# if we did ultimately fail, attempt to clean up
if not already_acquired:
self._best_effort_cleanup()
self._cleanup()
self.cancelled = False
raise
if gotten:
self.is_acquired = gotten
if not gotten and not already_acquired:
self._best_effort_cleanup()
self._cleanup()
return gotten
finally:
self._acquire_method_lock.release()
Expand Down Expand Up @@ -318,13 +318,18 @@ def _find_node(self):
def _delete_node(self, node):
self.client.delete(self.path + "/" + node)

def _best_effort_cleanup(self):
try:
node = self.node or self._find_node()
if node:
def _cleanup(self):
self._retry(
self._inner_cleanup,
)

def _inner_cleanup(self):
node = self.node or self._find_node()
if node:
try:
self._delete_node(node)
except KazooException: # pragma: nocover
pass
except NoNodeError: # pragma: nocover
pass

def release(self):
"""Release the lock immediately."""
Expand Down
Loading