Skip to content

fix: add mutex to LocalRepositoryCache to prevent concurrent map panic (rebase of #6055) - #6138

Open
louzt wants to merge 1 commit into
nektos:masterfrom
LOUST-PRO:pr-6055-rebased
Open

fix: add mutex to LocalRepositoryCache to prevent concurrent map panic (rebase of #6055)#6138
louzt wants to merge 1 commit into
nektos:masterfrom
LOUST-PRO:pr-6055-rebased

Conversation

@louzt

@louzt louzt commented Jul 28, 2026

Copy link
Copy Markdown

Summary

Fix concurrent map panic in LocalRepositoryCache when multiple goroutines call Fetch() simultaneously with overlapping cacheDir keys.

What

  • Adds cacheDirMu sync.RWMutex field on LocalRepositoryCache
  • Fetch() holds write lock when updating CacheDirCache
  • GetTarArchive() holds read lock when reading

Rebase 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.sh default BINDIR change in #6109 can be a separate PR if desired.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants