Skip to content

fix: add per-repo+branch mutex to prevent concurrent git lock errors#4014

Closed
fiftin with Copilot wants to merge 13 commits into
developfrom
copilot/fix-code-review-comment
Closed

fix: add per-repo+branch mutex to prevent concurrent git lock errors#4014
fiftin with Copilot wants to merge 13 commits into
developfrom
copilot/fix-code-review-comment

Conversation

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

GetRepositoryPlaybooks reuses a shared scratch checkout per repo+branch and runs git pull on every request. Concurrent requests for the same repo+branch race on .git/index.lock, causing corruption or failures.

  • Add a sync.Map-based per-directory mutex that serializes ValidateRepo/Clone/Pull for each unique repo+branch scratch checkout
lockKey := git.TmpDirName
mu, _ := repoBrowseMu.LoadOrStore(lockKey, &sync.Mutex{})
mu.(*sync.Mutex).Lock()
defer mu.(*sync.Mutex).Unlock()

rici4kubicek and others added 10 commits July 5, 2026 15:23
Adds GET /repositories/{id}/playbooks, returning .yml/.yaml paths found
in the repo (optionally at a given branch), so template creation can
offer a picker instead of requiring a hand-typed playbook path. Local
repos are read directly; git/ssh/https repos get a scratch checkout
per branch (git clone/pull is single-branch, so one dir per branch
avoids failed checkouts on branch switch).
Replaces the free-text playbook field with an autocomplete populated
from the new /repositories/{id}/playbooks endpoint, mirroring the
existing git-branch picker's pattern (falls back to free text if the
list can't be loaded). Reloads on repository or branch change.
Dedupe nopLogger into task_logger.NopLogger, shared by
api/projects/repository.go and db_lib test. Clean up orphaned/corrupt
clone directory on git.Clone() failure so retries don't get stuck on
ValidateRepo() passing against a broken checkout. Parallelize
loadBranches/loadPlaybooks in TemplateForm.vue since they're independent.
For local repositories, GET .../branches returns 400. Without a
try/catch, that rejection propagated out of loadBranches() and (now
that loadBranches/loadPlaybooks run via Promise.all) prevented the
playbook dropdown from populating. Mirrors the existing try/catch in
loadPlaybooks().
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI added 3 commits July 7, 2026 16:39
Concurrent requests for the same repo+branch can race on .git/index.lock
in the shared scratch checkout. Add a sync.Map-based per-directory mutex
that serializes ValidateRepo/Clone/Pull operations for each unique
repo+branch combination.
Copilot AI changed the title [WIP] Fix code based on the review comment fix: add per-repo+branch mutex to prevent concurrent git lock errors Jul 7, 2026
Copilot finished work on behalf of fiftin July 7, 2026 16:42
Copilot AI requested a review from fiftin July 7, 2026 16:42
@fiftin fiftin closed this Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants