Skip to content

Commit 1119413

Browse files
tonyseekjeffwidman
authored andcommitted
fix(recipe): conn hangs when TreeCache refreshing
The previous implementation of session watcher triggers blocked operations. If there is a huge tree in ZooKeeper, reconnecting event will lead an initialized TreeCache into a bad performance state, because the connection routine was blocked by the session watcher of TreeCache. This commit put those blocked operations into a background queue to fix this. There is an example code snippet: from kazoo.client import KazooClient from kazoo.recipe.cache import TreeCache client = KazooClient() client.start() cache = TreeCache(client, '/a-huge-tree') cache.start() # Wait the cache be initialized and trigger a connection lost event. client.get_children('/') # The connection is still broken The patch of this commit has been used in the production environment of https://github.com/eleme.
1 parent db0c2d4 commit 1119413

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

kazoo/recipe/cache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ def _session_watcher(self, state):
189189
if state == KazooState.SUSPENDED:
190190
self._publish_event(TreeEvent.CONNECTION_SUSPENDED)
191191
elif state == KazooState.CONNECTED:
192-
with handle_exception(self._error_listeners):
193-
self._root.on_reconnected()
194-
self._publish_event(TreeEvent.CONNECTION_RECONNECTED)
192+
# The session watcher should not be blocked
193+
self._in_background(self._root.on_reconnected)
194+
self._publish_event(TreeEvent.CONNECTION_RECONNECTED)
195195
elif state == KazooState.LOST:
196196
self._is_initialized = False
197197
self._publish_event(TreeEvent.CONNECTION_LOST)

0 commit comments

Comments
 (0)