locking: do not leave a lock behind when exclusive acquire times out#9871
Merged
ThomasWaldmann merged 1 commit intoJul 7, 2026
Merged
Conversation
When Lock.acquire() for an exclusive lock had created its lock and then timed out waiting for non-exclusive locks to go away, it raised LockTimeout without deleting the lock it had just created. That zombie exclusive lock then blocked all other clients until it expired as stale (up to 30 minutes) or until a client on the same host noticed the owning process was dead. Clients on other hosts were locked out for the full staleness period. Delete our lock before giving up. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9871 +/- ##
=======================================
Coverage 85.12% 85.12%
=======================================
Files 93 93
Lines 15458 15459 +1
Branches 2337 2337
=======================================
+ Hits 13158 13159 +1
Misses 1599 1599
Partials 701 701 ☔ View full report in Codecov by Harness. |
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.
Problem
When
Lock.acquire()for an exclusive lock succeeded in creating its lock object but then timed out waiting for existing non-exclusive locks to go away, it exited the retry loop viabreakand raisedLockTimeoutwithout deleting the exclusive lock it had just created.That zombie exclusive lock then blocked every other client:
process_alive()detects the dead owner process.Easy to hit in practice: e.g.
borg compact(exclusive) timing out against a long-runningborg create(shared) leaves the repo unusable for other clients for the staleness period.Fix
Delete our lock before giving up on the timeout path, same as the other back-off paths in
acquire()already do.Testing
Added
test_exclusive_lock_timeout_leaves_no_lock: a shared lock is held, an exclusive acquire times out, and the store must contain only the shared lock afterwards. The test fails against the unfixed code (the zombie exclusive lock is found) and passes with the fix.🤖 Generated with Claude Code