add a mutex to guard w.kv
This commit is contained in:
@ -92,6 +92,7 @@ func NewResolver(cfg etcdcl.Config) (naming.Resolver, error) {
|
|||||||
|
|
||||||
type watcher struct {
|
type watcher struct {
|
||||||
wr etcdcl.Watcher
|
wr etcdcl.Watcher
|
||||||
|
mu sync.Mutex
|
||||||
kv map[string]string
|
kv map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,6 +124,7 @@ func (w *watcher) Next(ctx context.Context) (nu []*naming.Update, err error) {
|
|||||||
if resp.Node.Dir {
|
if resp.Node.Dir {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
w.mu.Lock()
|
||||||
switch resp.Action {
|
switch resp.Action {
|
||||||
case "set":
|
case "set":
|
||||||
if resp.PrevNode == nil {
|
if resp.PrevNode == nil {
|
||||||
@ -149,6 +151,7 @@ func (w *watcher) Next(ctx context.Context) (nu []*naming.Update, err error) {
|
|||||||
})
|
})
|
||||||
delete(w.kv, resp.Node.Key)
|
delete(w.kv, resp.Node.Key)
|
||||||
}
|
}
|
||||||
|
w.mu.Unlock()
|
||||||
return nu, nil
|
return nu, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user