Skip to content

Commit

Permalink
Fix mutex locking on package
Browse files Browse the repository at this point in the history
  • Loading branch information
liamfallon committed Feb 18, 2025
1 parent 023cea1 commit 6aabb03
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/cache/crcache/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ func (r *cachedRepository) getPackages(ctx context.Context, filter repository.Li
// mutex must be held.
func (r *cachedRepository) getCachedPackages(ctx context.Context, forceRefresh bool) (map[repository.PackageKey]*cachedPackage, map[repository.PackageRevisionKey]*cachedPackageRevision, error) {
// must hold mutex

r.mutex.Lock()

packages := r.cachedPackages
packageRevisions := r.cachedPackageRevisions
err := r.refreshRevisionsError
Expand All @@ -168,11 +167,14 @@ func (r *cachedRepository) getCachedPackages(ctx context.Context, forceRefresh b
packages = nil
packageRevisions = nil

if err := r.repo.Refresh(ctx); err != nil {
r.mutex.Lock()
err := r.repo.Refresh(ctx)
r.mutex.Unlock()

if err != nil {
return nil, nil, err
}
}
r.mutex.Unlock()

if packages == nil {
packages, packageRevisions, err = r.refreshAllCachedPackages(ctx)
Expand Down

0 comments on commit 6aabb03

Please sign in to comment.