mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-21 21:27:16 +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 {
|
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…
x
Reference in New Issue
Block a user