From e2218c781984730f5ba3b2f272cca1d19ebb0c73 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 1 Aug 2019 23:03:11 +0100 Subject: [PATCH] Stop a goroutine leak in registy --- rcache.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/rcache.go b/rcache.go index e2e0da3..14bbbfb 100644 --- a/rcache.go +++ b/rcache.go @@ -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)