From 27c05669596f068bee65c6763a77bc6b7e9369c2 Mon Sep 17 00:00:00 2001 From: Guilhem Lettron Date: Sat, 8 Mar 2025 20:44:44 +0100 Subject: [PATCH] fix: list could lock if an error ocurred --- pkg/search.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/search.go b/pkg/search.go index 5471915fe..996c6c5c0 100644 --- a/pkg/search.go +++ b/pkg/search.go @@ -70,7 +70,6 @@ func DoSearch(stores []storetypes.KubeconfigStore, config *types.Config, stateDi resultChannel := make(chan DiscoveredContext) wgResultChannel := sync.WaitGroup{} - wgResultChannel.Add(len(stores)) for _, kubeconfigStore := range stores { logger := kubeconfigStore.GetLogger() @@ -138,7 +137,11 @@ func DoSearch(stores []storetypes.KubeconfigStore, config *types.Config, stateDi store.StartSearch(channel) }(kubeconfigStore, c) + wgResultChannel.Add(1) go func(store storetypes.KubeconfigStore, storeSearchChannel chan storetypes.SearchResult, index index.SearchIndex) { + + defer wgResultChannel.Done() + // remember the context to kubeconfig path mapping for this store // to write it to the index. Do not use the global "ContextToPathMapping" // as this contains contexts names from all stores combined @@ -204,9 +207,6 @@ func DoSearch(stores []storetypes.KubeconfigStore, config *types.Config, stateDi if len(localContextToPathMapping) > 0 { writeIndex(store, &index, localContextToPathMapping, localContextToTagsMapping) } - - // reading from this store is finished, decrease wait counter - wgResultChannel.Done() }(kubeconfigStore, c, *searchIndex) }