summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTW <tw@waldmann-edv.de>2023-11-18 18:22:52 +0100
committerGitHub <noreply@github.com>2023-11-18 18:22:52 +0100
commitdd7111410f6a0184f71945973855cebbd2929ed0 (patch)
treec7f5f941ea830667048b77d9146ec14943b3ef47
parente6d40f63d46b7fa9b4e3f549d66fdc5ffa1fd972 (diff)
parentd4833bfc4caebd90199f8d12b3431ff35e7c3b0a (diff)
Merge pull request #7942 from ThomasWaldmann/lockroster-remove-fix-1.11.1-maint
LockRoster.modify: no KeyError if element was already gone, fixes #7937
-rw-r--r--src/borg/locking.py9
-rw-r--r--src/borg/testsuite/locking.py2
2 files changed, 8 insertions, 3 deletions
diff --git a/src/borg/locking.py b/src/borg/locking.py
index 9a4267800..ada8ae87b 100644
--- a/src/borg/locking.py
+++ b/src/borg/locking.py
@@ -7,7 +7,7 @@ from . import platform
from .helpers import Error, ErrorWithTraceback
from .logger import create_logger
-ADD, REMOVE = 'add', 'remove'
+ADD, REMOVE, REMOVE2 = 'add', 'remove', 'remove2'
SHARED, EXCLUSIVE = 'shared', 'exclusive'
logger = create_logger(__name__)
@@ -285,6 +285,11 @@ class LockRoster:
if op == ADD:
elements.add(self.id)
elif op == REMOVE:
+ # note: we ignore it if the element is already not present anymore.
+ # this has been frequently seen in teardowns involving Repository.__del__ and Repository.__exit__.
+ elements.discard(self.id)
+ elif op == REMOVE2:
+ # needed for callers that do not want to ignore.
elements.remove(self.id)
else:
raise ValueError('Unknown LockRoster op %r' % op)
@@ -299,7 +304,7 @@ class LockRoster:
killing, self.kill_stale_locks = self.kill_stale_locks, False
try:
try:
- self.modify(key, REMOVE)
+ self.modify(key, REMOVE2)
except KeyError:
# entry was not there, so no need to add a new one, but still update our id
self.id = new_id
diff --git a/src/borg/testsuite/locking.py b/src/borg/testsuite/locking.py
index 64a792811..6975ed70f 100644
--- a/src/borg/testsuite/locking.py
+++ b/src/borg/testsuite/locking.py
@@ -162,7 +162,7 @@ class TestLock:
assert roster.get(SHARED) == {our_id}
assert roster.get(EXCLUSIVE) == set()
assert roster.get(SHARED) == set()
- with pytest.raises(KeyError):
+ with pytest.raises(NotLocked):
dead_lock.release()
with Lock(lockpath, id=cant_know_if_dead_id, exclusive=True):