Skip to content

Commit 83dca97

Browse files
qifei.wantonyseek
authored andcommitted
Fix the infinite refresh after root node deleted
1 parent e5cb097 commit 83dca97

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

kazoo/recipe/cache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,14 @@ def _refresh(self):
248248
self._refresh_children()
249249

250250
def _refresh_data(self):
251-
self._tree._outstanding_ops += 1
252251
self._call_client('get', self._path)
253252

254253
def _refresh_children(self):
255254
# TODO max-depth checking support
256-
self._tree._outstanding_ops += 1
257255
self._call_client('get_children', self._path)
258256

259257
def _call_client(self, method_name, path, *args):
258+
self._tree._outstanding_ops += 1
260259
callback = functools.partial(
261260
self._tree._in_background, self._process_result,
262261
method_name, path)
@@ -281,7 +280,8 @@ def _process_result(self, method_name, path, result):
281280
logger.debug('process_result: %s %s', method_name, path)
282281
if method_name == 'exists':
283282
assert self._parent is None, 'unexpected EXISTS on non-root'
284-
if result.successful():
283+
# the value of result will be set with `None` if node not exists.
284+
if result.get() is not None:
285285
if self._state == self.STATE_DEAD:
286286
self._state = self.STATE_PENDING
287287
self.on_created()

kazoo/tests/test_cache.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ def test_root_recreated(self):
256256
eq_(event.event_data.path, self.path)
257257
eq_(event.event_data.stat.version, 0)
258258

259+
self.assertTrue(
260+
self.cache._outstanding_ops >= 0,
261+
'unexpected outstanding ops %r' % self.cache._outstanding_ops)
262+
259263
def test_exception_handler(self):
260264
error_value = FakeException()
261265
error_handler = Mock()

0 commit comments

Comments
 (0)