From 3f63b53090db85a5da27ad24286a8bdb1ab1f2f9 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 22 Jul 2023 23:29:14 +0200 Subject: [PATCH] lock: Shrink critical section in RefreshStaleLock A cleaning up after a failed lock refresh attempt does not require a mutex. --- internal/restic/lock.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/restic/lock.go b/internal/restic/lock.go index b1584aa19..a65ed6b5c 100644 --- a/internal/restic/lock.go +++ b/internal/restic/lock.go @@ -306,15 +306,15 @@ func (l *Lock) RefreshStaleLock(ctx context.Context) error { return err } - l.lock.Lock() - defer l.lock.Unlock() - if !exists { // cleanup replacement lock _ = l.repo.Backend().Remove(context.TODO(), Handle{Type: LockFile, Name: id.String()}) return ErrRemovedLock } + l.lock.Lock() + defer l.lock.Unlock() + debug.Log("new lock ID %v", id) oldLockID := l.lockID l.lockID = &id