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:
parent
33fff02a62
commit
b0db594829
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user