From b0db5948293bba76a6f80f67e9e8f57af726426f Mon Sep 17 00:00:00 2001 From: soukengo Date: Sun, 1 Jan 2023 20:10:57 +0800 Subject: [PATCH] fix(registry): add zookeeper exists watcher when the node does not exist (#2555) * fix(registry): add zookeeper exists watcher when the node does not exist * fix(registry): add zookeeper exists watcher when the node does not exist Co-authored-by: soukengo --- contrib/registry/zookeeper/watcher.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/contrib/registry/zookeeper/watcher.go b/contrib/registry/zookeeper/watcher.go index ddb98a84c..1f71d07ba 100644 --- a/contrib/registry/zookeeper/watcher.go +++ b/contrib/registry/zookeeper/watcher.go @@ -40,13 +40,21 @@ func (w *watcher) watch(ctx context.Context) { // 每次 watch 只有一次有效期 所以循环 watch _, _, ch, err := w.conn.ChildrenW(w.prefix) if err != nil { - w.event <- zk.Event{Err: err} + // If the target service node has not been created + if errors.Is(err, zk.ErrNoNode) { + // Add watcher for the node exists + _, _, ch, err = w.conn.ExistsW(w.prefix) + } + if err != nil { + w.event <- zk.Event{Err: err} + return + } } select { case <-ctx.Done(): return - default: - w.event <- <-ch + case ev := <-ch: + w.event <- ev } } }