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 <soukengo@163.com>
pull/2598/head
soukengo 2 years ago committed by GitHub
parent 33fff02a62
commit b0db594829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      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
}
}
}

Loading…
Cancel
Save