From 5d62251862d3e461362e51c5286198e6c7e7ed3a Mon Sep 17 00:00:00 2001 From: John Belamaric Date: Mon, 20 Nov 2023 13:47:46 -0800 Subject: [PATCH] Before starting a new watcher, reap dead ones Signed-off-by: John Belamaric --- porch/pkg/engine/watchermanager.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/porch/pkg/engine/watchermanager.go b/porch/pkg/engine/watchermanager.go index f6ec874b9..8217404d0 100644 --- a/porch/pkg/engine/watchermanager.go +++ b/porch/pkg/engine/watchermanager.go @@ -65,6 +65,18 @@ func (r *watcherManager) WatchPackageRevisions(ctx context.Context, filter repos r.mutex.Lock() defer r.mutex.Unlock() + // reap any dead watchers + for i, watcher := range r.watchers { + if watcher == nil { + continue + } + if err := watcher.isDoneFunction(); err != nil { + klog.Infof("stopping watcher in reaper: %v", err) + r.watchers[i] = nil + continue + } + } + w := &watcher{ isDoneFunction: ctx.Err, callback: callback,