Skip to content

Commit 92b4dba

Browse files
committed
Ensure watches are notified when connection state is lost
- This behaviour matches the reference implementation in Zookeeper - New EventType added: NONE - Path defaults to None as in reference implementation
1 parent f055dc0 commit 92b4dba

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

kazoo/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@
4444
Sync,
4545
Transaction
4646
)
47+
from kazoo.protocol.states import Callback
48+
from kazoo.protocol.states import EventType
4749
from kazoo.protocol.states import KazooState
4850
from kazoo.protocol.states import KeeperState
51+
from kazoo.protocol.states import WatchedEvent
4952
from kazoo.retry import KazooRetry
5053
from kazoo.security import ACL
5154
from kazoo.security import OPEN_ACL_UNSAFE
@@ -305,9 +308,20 @@ def _reset(self):
305308
self._protocol_version = None
306309

307310
def _reset_watchers(self):
311+
watchers = []
312+
for child_watchers in six.itervalues(self._child_watchers):
313+
watchers.extend(child_watchers)
314+
315+
for data_watchers in six.itervalues(self._data_watchers):
316+
watchers.extend(data_watchers)
317+
308318
self._child_watchers = defaultdict(set)
309319
self._data_watchers = defaultdict(set)
310320

321+
ev = WatchedEvent(EventType.NONE, self._state, None)
322+
for watch in watchers:
323+
self.handler.dispatch_callback(Callback("watch", watch, (ev,)))
324+
311325
def _reset_session(self):
312326
self._session_id = None
313327
self._session_passwd = b'\x00' * 16

kazoo/protocol/states.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,19 @@ class EventType(object):
9393
removed). This event does not indicate the data for a child
9494
node has changed, which must have its own watch established.
9595
96+
.. attribute:: NONE
97+
98+
The connection state has been altered.
99+
96100
"""
97101
CREATED = 'CREATED'
98102
DELETED = 'DELETED'
99103
CHANGED = 'CHANGED'
100104
CHILD = 'CHILD'
105+
NONE = 'NONE'
101106

102107
EVENT_TYPE_MAP = {
108+
-1:EventType.NONE,
103109
1: EventType.CREATED,
104110
2: EventType.DELETED,
105111
3: EventType.CHANGED,

0 commit comments

Comments
 (0)