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. 12
      contrib/registry/zookeeper/watcher.go

@ -39,14 +39,22 @@ func (w *watcher) watch(ctx context.Context) {
for { for {
// 每次 watch 只有一次有效期 所以循环 watch // 每次 watch 只有一次有效期 所以循环 watch
_, _, ch, err := w.conn.ChildrenW(w.prefix) _, _, ch, err := w.conn.ChildrenW(w.prefix)
if err != nil {
// 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 { if err != nil {
w.event <- zk.Event{Err: err} w.event <- zk.Event{Err: err}
return
}
} }
select { select {
case <-ctx.Done(): case <-ctx.Done():
return return
default: case ev := <-ch:
w.event <- <-ch w.event <- ev
} }
} }
} }

Loading…
Cancel
Save