Fix: Data Race Bug detected via TestConcurrenyDownloadIndex

Signed-off-by: haojingcn <mhjlq1989@gmail.com>
pull/31630/head
haojingcn 10 months ago
parent e1bdab214f
commit 4b6a4b6932

@ -28,6 +28,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"sync"
"helm.sh/helm/v4/internal/fileutil" "helm.sh/helm/v4/internal/fileutil"
"helm.sh/helm/v4/pkg/getter" "helm.sh/helm/v4/pkg/getter"
@ -53,6 +54,7 @@ type ChartRepository struct {
IndexFile *IndexFile IndexFile *IndexFile
Client getter.Getter Client getter.Getter
CachePath string CachePath string
mutex sync.RWMutex
} }
// NewChartRepository constructs ChartRepository // NewChartRepository constructs ChartRepository
@ -77,6 +79,9 @@ func NewChartRepository(cfg *Entry, getters getter.Providers) (*ChartRepository,
// DownloadIndexFile fetches the index from a repository. // DownloadIndexFile fetches the index from a repository.
func (r *ChartRepository) DownloadIndexFile() (string, error) { func (r *ChartRepository) DownloadIndexFile() (string, error) {
r.mutex.Lock()
defer r.mutex.Unlock()
indexURL, err := ResolveReferenceURL(r.Config.URL, "index.yaml") indexURL, err := ResolveReferenceURL(r.Config.URL, "index.yaml")
if err != nil { if err != nil {
return "", err return "", err

Loading…
Cancel
Save