From 804867d3ad976f0681c3d1c0f6cd8e9fc539a07b Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 13 Jan 2023 21:19:47 +0100 Subject: [PATCH 1/3] bugfix: thread id must be parsed as hex from lock file name --- src/borg/locking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/borg/locking.py b/src/borg/locking.py index ecd6d27ca..89ff02ebd 100644 --- a/src/borg/locking.py +++ b/src/borg/locking.py @@ -195,7 +195,7 @@ class ExclusiveLock: host_pid, thread_str = name.rsplit('-', 1) host, pid_str = host_pid.rsplit('.', 1) pid = int(pid_str) - thread = int(thread_str) + thread = int(thread_str, 16) except ValueError: # Malformed lock name? Or just some new format we don't understand? logger.error("Found malformed lock %s in %s. Please check/fix manually.", name, self.path) From 91104674e76bf29710d2d45891eda7305664170a Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 13 Jan 2023 19:17:48 +0100 Subject: [PATCH 2/3] use os.replace not os.rename --- src/borg/locking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/borg/locking.py b/src/borg/locking.py index 89ff02ebd..4192f1f10 100644 --- a/src/borg/locking.py +++ b/src/borg/locking.py @@ -139,7 +139,7 @@ class ExclusiveLock: timer = TimeoutTimer(timeout, sleep).start() while True: try: - os.rename(temp_path, self.path) + os.replace(temp_path, self.path) except OSError: # already locked if self.by_me(): return self From 16eb38e20a6c6f628e230949091bc873980cde1e Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 13 Jan 2023 19:56:46 +0100 Subject: [PATCH 3/3] fix host, pid, tid order using "differenthost" (== not the current hostname) makes the process_alive check always return True (to play safe, because in can not check for processes on other hosts). --- src/borg/testsuite/locking.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/borg/testsuite/locking.py b/src/borg/testsuite/locking.py index 7a0f219cd..b8fb67797 100644 --- a/src/borg/testsuite/locking.py +++ b/src/borg/testsuite/locking.py @@ -157,8 +157,11 @@ class TestExclusiveLock: exception_counter = SynchronizedCounter() print_lock = ThreadingLock() thread = None + host_id, process_id = "differenthost", 1234 for thread_id in range(RACE_TEST_NUM_THREADS): - thread = Thread(target=acquire_release_loop, args=(('foo', thread_id, 0), RACE_TEST_DURATION, thread_id, lock_owner_counter, exception_counter, print_lock, thread)) + thread = Thread(target=acquire_release_loop, + args=((host_id, process_id, thread_id), RACE_TEST_DURATION, thread_id, + lock_owner_counter, exception_counter, print_lock, thread)) thread.start() thread.join() # joining the last thread