redis: always remove lock from acquired lock when release()ing

The failure scenarios where LockError is raised is either:
- Lock is not locked. Then it should not be in _acquired_locks, so discard
  should be a no-op.
- Token changed. That can happen if the lock timed-out (and somebody else
  grabbed it). Then the lock is not longer owned anyway so let's remove it.

If releasing the lock fails, there's no way heartbeat will work anyway. So just
remove the lock from acquired locks and let it die anyway.

Change-Id: I44db39e83db7e6c0f17079584e49c8de34b51ce1
This commit is contained in:
Julien Danjou 2017-08-14 10:18:09 +02:00
parent a25815d9a8
commit 3f25d41182
1 changed files with 2 additions and 1 deletions

View File

@ -102,7 +102,8 @@ class RedisLock(locking.Lock):
except exceptions.LockError as e:
LOG.error("Unable to release lock '%r': %s", self, e)
return False
self._coord._acquired_locks.discard(self)
finally:
self._coord._acquired_locks.discard(self)
return True
def heartbeat(self):