fix: add mutex to LocalRepositoryCache to prevent concurrent map panic (rebase of #6055) - #6138
Open
louzt wants to merge 1 commit into
Open
fix: add mutex to LocalRepositoryCache to prevent concurrent map panic (rebase of #6055)#6138louzt wants to merge 1 commit into
louzt wants to merge 1 commit into
Conversation
LocalRepositoryCache.CacheDirCache is a plain map[string]string
accessed concurrently by Fetch (write) and GetTarArchive (read)
when multiple matrix jobs resolve --local-repository actions in
parallel. This causes:
fatal error: concurrent map read and map write
goroutine ... [running]:
LocalRepositoryCache.GetTarArchive(...)
local_repository_cache.go:47
Add a sync.RWMutex to serialize access to CacheDirCache:
- Fetch: write lock when updating the cache
- GetTarArchive: read lock when looking up cached paths
LocalRepositories is set at initialization and only read after,
so it does not need synchronization.
This is the same class of bug as nektos#6028 (fixed in nektos#6029 for
GoGitActionCache), but in the --local-repository code path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix concurrent map panic in
LocalRepositoryCachewhen multiple goroutines callFetch()simultaneously with overlapping cacheDir keys.What
cacheDirMu sync.RWMutexfield onLocalRepositoryCacheFetch()holds write lock when updatingCacheDirCacheGetTarArchive()holds read lock when readingRebase status
Rebased against current master (4f41128). Zero conflicts. Builds clean. Unit tests pass under
-race -short.Note
PR #6109 from @aruneshdwivedi0 overlaps with this fix (same concern, different mutex name) — closing in favor of this PR for the narrower scope. The
install.shdefault BINDIR change in #6109 can be a separate PR if desired.