repository: remove redundant mutex in checkForOtherLocks

forAllLocks already serializes the callback calls. Still has to create a
copy of checkedIDs to prevent a data race between forAllLocks and the
callback.
This commit is contained in:
Michael Eischer
2026-06-08 22:14:12 +02:00
parent 6fe10a72eb
commit 406dec29a7
+1 -4
View File
@@ -173,8 +173,7 @@ func (l *lockHandle) checkForOtherLocks(ctx context.Context) error {
delay *= 2
}
// Store updates in new IDSet to prevent data races
var m sync.Mutex
// Store updates in new IDSet to prevent data races with Has() check in forAllLocks
newCheckedIDs := checkedIDs.Clone()
err = forAllLocks(ctx, l.repo, checkedIDs, func(id restic.ID, lock *lockHandle, err error) error {
if err != nil {
@@ -189,9 +188,7 @@ func (l *lockHandle) checkForOtherLocks(ctx context.Context) error {
}
// valid locks will remain valid
m.Lock()
newCheckedIDs.Insert(id)
m.Unlock()
return nil
})
checkedIDs = newCheckedIDs