1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-03-19 21:18:07 +02:00

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>
This commit is contained in:
soukengo 2023-01-01 20:10:57 +08:00 committed by GitHub
parent 33fff02a62
commit b0db594829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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