1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00

Stop a goroutine leak in registy

This commit is contained in:
Asim Aslam 2019-08-01 23:03:11 +01:00
parent cdf0f14d58
commit b806e7bdf5

View File

@ -325,18 +325,27 @@ func (c *cache) run(service string) {
// watch loops the next event and calls update
// it returns if there's an error
func (c *cache) watch(w registry.Watcher) error {
defer w.Stop()
// used to stop the watch
stop := make(chan bool)
// manage this loop
go func() {
defer w.Stop()
select {
// wait for exit
<-c.exit
w.Stop()
case <-c.exit:
return
// we've been stopped
case <-stop:
return
}
}()
for {
res, err := w.Next()
if err != nil {
close(stop)
return err
}
c.update(res)