Skip to content

locking: do not leave a lock behind when exclusive acquire times out#9871

Merged
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:fix-lock-acquire-timeout
Jul 7, 2026
Merged

locking: do not leave a lock behind when exclusive acquire times out#9871
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:fix-lock-acquire-timeout

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Member

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 via break and raised LockTimeout without deleting the exclusive lock it had just created.

That zombie exclusive lock then blocked every other client:

  • clients on other hosts were locked out until the lock expired as stale (up to 30 minutes by default),
  • clients on the same host recovered earlier only because process_alive() detects the dead owner process.

Easy to hit in practice: e.g. borg compact (exclusive) timing out against a long-running borg 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

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

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.12%. Comparing base (cbc94ae) to head (88f470e).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

@ThomasWaldmann ThomasWaldmann merged commit 3539fcc into borgbackup:master Jul 7, 2026
19 checks passed
@ThomasWaldmann ThomasWaldmann deleted the fix-lock-acquire-timeout branch July 7, 2026 02:47
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.

1 participant