From 4ebffe1530fc347cc0f9c13f60f4cafbda6ea363 Mon Sep 17 00:00:00 2001 From: Kebe Date: Thu, 21 Apr 2022 11:38:56 +0800 Subject: [PATCH] > fix watcher stop error --- watcher/watcher.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/watcher/watcher.go b/watcher/watcher.go index 26165bf..c0a2144 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -135,6 +135,11 @@ func (w *watcher) watchResources(r store.GroupVersionResource, cluster string) { config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() rt, _ := rest.RESTClientFor(&config) for { + select { + case <-w.stop: + return + default: + } ctx, calcel := context.WithTimeout(context.Background(), time.Hour) url := "" if r.Group == "" { @@ -146,7 +151,7 @@ func (w *watcher) watchResources(r store.GroupVersionResource, cluster string) { ww, err := rt.Get().RequestURI(url).Timeout(time.Hour).Watch(ctx) if err != nil { log.Errorf("cluster(%s): create watcher for %s error: %v", cluster, url, err) - time.Sleep(time.Second * 3) + time.Sleep(time.Second * 15) } else { resultChan: for { @@ -177,7 +182,7 @@ func (w *watcher) watchResources(r store.GroupVersionResource, cluster string) { } case <-w.stop: ww.Stop() - break resultChan + return } } }