diff --git a/controllers/remote/keyedmutex.go b/controllers/remote/keyedmutex.go index b8f1d6cb750a..58dbd86d54c6 100644 --- a/controllers/remote/keyedmutex.go +++ b/controllers/remote/keyedmutex.go @@ -27,13 +27,13 @@ import ( // A second Lock call if the lock is already held for a key returns false. type keyedMutex struct { locksMtx sync.Mutex - locks map[client.ObjectKey]bool + locks map[client.ObjectKey]struct{} } // newKeyedMutex creates a new keyed mutex ready for use. func newKeyedMutex() *keyedMutex { return &keyedMutex{ - locks: make(map[client.ObjectKey]bool), + locks: make(map[client.ObjectKey]struct{}), } } @@ -51,7 +51,7 @@ func (k *keyedMutex) TryLock(key client.ObjectKey) bool { } // Lock doesn't exist yet, create the lock. - k.locks[key] = true + k.locks[key] = struct{}{} return true } @@ -61,7 +61,6 @@ func (k *keyedMutex) Unlock(key client.ObjectKey) { k.locksMtx.Lock() defer k.locksMtx.Unlock() - if k.locks[key] { - delete(k.locks, key) - } + // Remove the lock if it exists. + delete(k.locks, key) }