From 90e39fa3f56e2b8e8eac0e9a8ca78dfc8a009e8e Mon Sep 17 00:00:00 2001 From: Sergey Kacheev Date: Sat, 11 Sep 2021 23:32:20 +0700 Subject: [PATCH] fix the set of events received by ChildrenW In accordance with https://github.com/apache/zookeeper/blob/c74658d398cdc1d207aa296cb6e20de00faec03e/zookeeper-client/zookeeper-client-c/src/zk_hashtable.c#L297-L314 ChildrenW should not receive data change events of the observed node. --- conn.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/conn.go b/conn.go index 43656c74..20b1fd09 100644 --- a/conn.go +++ b/conn.go @@ -801,7 +801,7 @@ func (c *Conn) recvLoop(conn net.Conn) error { if res.Xid == -1 { res := &watcherEvent{} - _, err := decodePacket(buf[16:blen], res) + _, err = decodePacket(buf[16:blen], res) if err != nil { return err } @@ -816,15 +816,17 @@ func (c *Conn) recvLoop(conn net.Conn) error { switch res.Type { case EventNodeCreated: wTypes = append(wTypes, watchTypeExist) - case EventNodeDeleted, EventNodeDataChanged: - wTypes = append(wTypes, watchTypeExist, watchTypeData, watchTypeChild) + case EventNodeDataChanged: + wTypes = append(wTypes, watchTypeExist, watchTypeData) case EventNodeChildrenChanged: wTypes = append(wTypes, watchTypeChild) + case EventNodeDeleted: + wTypes = append(wTypes, watchTypeExist, watchTypeData, watchTypeChild) } c.watchersLock.Lock() for _, t := range wTypes { wpt := watchPathType{res.Path, t} - if watchers := c.watchers[wpt]; watchers != nil && len(watchers) > 0 { + if watchers := c.watchers[wpt]; len(watchers) > 0 { for _, ch := range watchers { ch <- ev close(ch)