Skip to content

Commit 9b0a793

Browse files
packysaucejeffwidman
authored andcommitted
fix (recipe): Don't set creation watch on lock predecessor node
Using exists will register a creation, as well as update and deletion watch on the given node. This introduces a race, where the predecessor node can get deleted between the call to getChildren() and exists(). If that happens, the exists() sets a create watch on a node that will never be created, leaks a create watch.
1 parent 2385079 commit 9b0a793

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

kazoo/recipe/lock.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,14 @@ def _inner_acquire(self, blocking, timeout):
246246
predecessor = self.path + "/" + predecessor
247247
self.client.add_listener(self._watch_session)
248248
try:
249-
if self.client.exists(predecessor, self._watch_predecessor):
250-
self.wake_event.wait(timeout)
251-
if not self.wake_event.isSet():
252-
raise LockTimeout("Failed to acquire lock on %s after "
253-
"%s seconds" % (self.path, timeout))
249+
self.client.get(predecessor, self._watch_predecessor)
250+
except NoNodeError:
251+
pass # predecessor has already been deleted
252+
else:
253+
self.wake_event.wait(timeout)
254+
if not self.wake_event.isSet():
255+
raise LockTimeout("Failed to acquire lock on %s after "
256+
"%s seconds" % (self.path, timeout))
254257
finally:
255258
self.client.remove_listener(self._watch_session)
256259

0 commit comments

Comments
 (0)