fix(vendor): lock vendor cache/Hub during sync to prevent concurrent-run corruption - #39
Open
HuangChenning wants to merge 1 commit into
Open
fix(vendor): lock vendor cache/Hub during sync to prevent concurrent-run corruption#39HuangChenning wants to merge 1 commit into
HuangChenning wants to merge 1 commit into
Conversation
…run corruption Major changes: - Add vendor.AcquireSyncLock, a flock-based exclusive lock over the vendor cache root (same pattern as the existing update lock) - runVendorSync acquires the lock before touching any vendor entry and holds it for the whole run, failing fast with an actionable error if another sync is already in progress Minor improvements: - Add lock tests: second concurrent acquire fails, re-acquire after release succeeds Manually verified: running two `axon vendor sync` invocations at the same time previously corrupted the losing process's rsync/git state (rsync getcwd() errors, git fetch lock conflicts). With this lock, the second process now fails immediately with a clear message instead. Closes kamusis#38
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.
Description
axon vendor syncreads/writes the shared vendor cache(
~/.axon/cache/vendors/<owner>/<repo>) and the Hub with no locking.Two concurrent
axon vendor syncruns race on the samegit fetch/checkoutandrsync -a --deleteoperations against the samedirectories — reproduced directly (see #38): the losing process hits
rsync: [Receiver] getcwd(): No such file or directory (2)/rsync error ... code 3and/orgit fetch failed ... exit status 128.Changes
vendor.AcquireSyncLock, aflock-based exclusive lock over thevendor cache root — same pattern already used for
axon update(
acquireUpdateLockinupdate.go)runVendorSyncacquires the lock right after validating the configand before touching any vendor entry, and releases it via
deferwhen the command returns
can take a while, so failing fast with an actionable message is more
useful than waiting on an unknown-duration run
Type of Change
How to Test
Manually verified by launching two
axon vendor syncprocesses at thesame time against the same
axon.yaml:getcwd()/exit-3errors and git fetch lock conflicts on several vendors
Error: another \axon vendor sync` is already running (lock: ...)`while the first process completes normally
Also added
internal/vendor/lock_test.go:AcquireSyncLockcall fails while the firstlock is held
release()succeedsChecklist
Related Issues
Closes #38