From 0300d0414836f70d19d4a10b44f1fcf30a78a01a Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Date: Tue, 31 Oct 2023 12:19:06 +0200 Subject: [PATCH 1/2] fix: fix vulncheck's repo cache to be concurrency-friendly This uses xsync's Map instead of a bare map. This way we can avoid the concurrency issues. --- internal/engine/eval/vulncheck/pkgdb.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/engine/eval/vulncheck/pkgdb.go b/internal/engine/eval/vulncheck/pkgdb.go index 9ce5be148e..a90f6c5d0f 100644 --- a/internal/engine/eval/vulncheck/pkgdb.go +++ b/internal/engine/eval/vulncheck/pkgdb.go @@ -25,6 +25,7 @@ import ( "net/url" "strings" + "github.com/puzpuzpuz/xsync" "github.com/stacklok/mediator/internal/util" pb "github.com/stacklok/mediator/pkg/api/protobuf/go/minder/v1" ) @@ -57,17 +58,17 @@ type RepoQuerier interface { } type repoCache struct { - cache map[string]RepoQuerier + cache *xsync.MapOf[string, RepoQuerier] } func newRepoCache() *repoCache { return &repoCache{ - cache: make(map[string]RepoQuerier), + cache: xsync.NewMapOf[RepoQuerier](), } } func (rc *repoCache) newRepository(ecoConfig *ecosystemConfig) (RepoQuerier, error) { - if repo, exists := rc.cache[ecoConfig.Name]; exists { + if repo, exists := rc.cache.Load(ecoConfig.Name); exists { return repo, nil } @@ -83,7 +84,7 @@ func (rc *repoCache) newRepository(ecoConfig *ecosystemConfig) (RepoQuerier, err return nil, fmt.Errorf("unknown ecosystem: %s", ecoConfig.Name) } - rc.cache[ecoConfig.Name] = repo + rc.cache.Store(ecoConfig.Name, repo) return repo, nil } From a0796c5aed2ba322d5ec5c029db93a42eef37d9b Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Date: Tue, 31 Oct 2023 12:52:18 +0200 Subject: [PATCH 2/2] run golangci-lint fix --- internal/engine/eval/vulncheck/pkgdb.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/engine/eval/vulncheck/pkgdb.go b/internal/engine/eval/vulncheck/pkgdb.go index a90f6c5d0f..d910e82787 100644 --- a/internal/engine/eval/vulncheck/pkgdb.go +++ b/internal/engine/eval/vulncheck/pkgdb.go @@ -26,6 +26,7 @@ import ( "strings" "github.com/puzpuzpuz/xsync" + "github.com/stacklok/mediator/internal/util" pb "github.com/stacklok/mediator/pkg/api/protobuf/go/minder/v1" )