Stop a goroutine leak in registy
This commit is contained in:
parent
cdf0f14d58
commit
b806e7bdf5
15
registry/cache/rcache.go
vendored
15
registry/cache/rcache.go
vendored
@ -325,18 +325,27 @@ func (c *cache) run(service string) {
|
|||||||
// watch loops the next event and calls update
|
// watch loops the next event and calls update
|
||||||
// it returns if there's an error
|
// it returns if there's an error
|
||||||
func (c *cache) watch(w registry.Watcher) error {
|
func (c *cache) watch(w registry.Watcher) error {
|
||||||
defer w.Stop()
|
// used to stop the watch
|
||||||
|
stop := make(chan bool)
|
||||||
|
|
||||||
// manage this loop
|
// manage this loop
|
||||||
go func() {
|
go func() {
|
||||||
|
defer w.Stop()
|
||||||
|
|
||||||
|
select {
|
||||||
// wait for exit
|
// wait for exit
|
||||||
<-c.exit
|
case <-c.exit:
|
||||||
w.Stop()
|
return
|
||||||
|
// we've been stopped
|
||||||
|
case <-stop:
|
||||||
|
return
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
res, err := w.Next()
|
res, err := w.Next()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
close(stop)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.update(res)
|
c.update(res)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user