Skip to content

Commit

Permalink
Protect error read with the RLock too
Browse files Browse the repository at this point in the history
Signed-off-by: John Belamaric <[email protected]>
  • Loading branch information
johnbelamaric committed Nov 20, 2023
1 parent b414ff3 commit bd723e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion porch/pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ func (c *Cache) OpenRepository(ctx context.Context, repositorySpec *configapi.Re
cr = newRepository(key, repositorySpec, r, c.objectNotifier, c.metadataStore, c.repoSyncFrequency)
c.repositories[key] = cr
}
} else {
// If there is an error from the background refresh goroutine, return it.
if err := cr.getRefreshError(); err != nil {
return nil, err
}
}
return cr, cr.refreshRevisionsError
return cr, nil

default:
return nil, fmt.Errorf("type %q not supported", repositoryType)
Expand Down
7 changes: 7 additions & 0 deletions porch/pkg/cache/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ func (r *cachedRepository) ListFunctions(ctx context.Context) ([]repository.Func
return functions, nil
}

func (r *cachedRepository) getRefreshError() error {
r.mutex.RLock()
defer r.mutex.RUnlock()

return r.refreshRevisionsError
}

func (r *cachedRepository) getPackageRevisions(ctx context.Context, filter repository.ListPackageRevisionFilter) ([]repository.PackageRevision, error) {
packageRevisions, err := r.getCachedPackageRevisions(ctx)
if err != nil {
Expand Down

0 comments on commit bd723e0

Please sign in to comment.