From 063ba86447f30724d6c1ae403a11f1f1beff8865 Mon Sep 17 00:00:00 2001 From: yxxhero <11087727+yxxhero@users.noreply.github.com> Date: Wed, 15 Mar 2023 15:42:16 +0800 Subject: [PATCH] fix concurrency issue (#742) Signed-off-by: yxxhero --- pkg/state/state.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/state/state.go b/pkg/state/state.go index 08c74d67..e0c05948 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -1098,7 +1098,9 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre releases := releasesNeedCharts(selected) - temp := make(map[PrepareChartKey]string, len(releases)) + var prepareChartInfoMutex sync.Mutex + + prepareChartInfo := make(map[PrepareChartKey]string, len(releases)) errs := []error{} @@ -1302,11 +1304,15 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre return } - temp[PrepareChartKey{ - Namespace: downloadRes.releaseNamespace, - KubeContext: downloadRes.releaseContext, - Name: downloadRes.releaseName, - }] = downloadRes.chartPath + func() { + prepareChartInfoMutex.Lock() + defer prepareChartInfoMutex.Unlock() + prepareChartInfo[PrepareChartKey{ + Namespace: downloadRes.releaseNamespace, + KubeContext: downloadRes.releaseContext, + Name: downloadRes.releaseName, + }] = downloadRes.chartPath + }() if downloadRes.buildDeps { builds = append(builds, downloadRes) @@ -1325,7 +1331,7 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre } } - return temp, nil + return prepareChartInfo, nil } // nolint: unparam