PLT-0000 fix(deploy): serialize repocache access to prevent stale git locks#151
Open
uptickmetachu wants to merge 2 commits intodevelopfrom
Open
PLT-0000 fix(deploy): serialize repocache access to prevent stale git locks#151uptickmetachu wants to merge 2 commits intodevelopfrom
uptickmetachu wants to merge 2 commits intodevelopfrom
Conversation
Replace the global asyncio.Semaphore guarding only the initial clone with per-repo asyncio.Locks held across both cache init and the cp -r into the per-deploy temp dir. Previously the cache-exists check ran outside the lock and the copy was fully unlocked, so a second worker could read the cache mid-clone and pull a half-written .git/index.lock into the temp dir, breaking the subsequent checkout. fetch/checkout remain outside the lock since each temp dir is private, preserving parallelism across concurrent deploys. A defensive rm -f of .git/index.lock after the copy handles any stale lock that might still slip through. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Docker ImagesCommit:
|
Mise started failing to install python@3.12.1 with "No GitHub artifact attestations found". Disable the attestation check in CI so the install step succeeds; the python version is already pinned via .mise.toml. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Motivation
The gitops pod in the
gitopsnamespace failed a deployment with:This wasn't disk pressure — node and pod both had plenty of headroom. The root cause is a race in
gitops_server/utils/git.py::temp_repo:repo_locksemaphore, so two concurrent workers could both decide the cache needs cloning.cp -r <cache> <tmp>step was fully unlocked. While one worker was (re)cloning the cache, another'scp -rcould snapshot the cache mid-write and pull a half-written.git/index.lockinto its private temp dir, breaking the subsequentgit checkout.Under the webhook storm right after a pod restart (~16 concurrent deploys), this race fires and whole deploys fail.
Changes
asyncio.Semaphore(1)with per-repoasyncio.Lock(_get_cache_lock(url)). Concurrent deploys against different repos still run in parallel.cp -r <cache> <tmp>too, so readers can't observe a partially written cache.git fetch/git checkoutstay outside the lock: the temp dir is private per deploy, so this keeps the heavy network work parallel.rm -f <tmp>/.git/index.lockafter the copy as belt-and-braces in case a stale lock ever lands on disk from another path.Test plan
uv run pytest tests/test_git.py— all 3 tests passuv run ruff check/ruff format --check— cleanUnable to create '.git/index.lock'failuresFollow-ups (not in this PR)
The same incident also showed the gitops pod getting SIGKILL'd (exit 137) from liveness probe timeouts during deployment storms —
/liveztimes out when the event loop is busy coordinating many subprocesses. Worth raisinglivenessProbe.timeoutSecondsand/or moving the probe off the busy loop in a follow-up.🤖 Generated with Claude Code