mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Fix dropping locks on shut down (#10433)
This commit is contained in:
parent
96e63ec7bf
commit
54389d5697
1
changelog.d/10433.bugfix
Normal file
1
changelog.d/10433.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Fix error while dropping locks on shutdown. Introduced in v1.38.0.
|
@ -78,7 +78,11 @@ class LockStore(SQLBaseStore):
|
||||
"""Called when the server is shutting down"""
|
||||
logger.info("Dropping held locks due to shutdown")
|
||||
|
||||
for (lock_name, lock_key), token in self._live_tokens.items():
|
||||
# We need to take a copy of the tokens dict as dropping the locks will
|
||||
# cause the dictionary to change.
|
||||
tokens = dict(self._live_tokens)
|
||||
|
||||
for (lock_name, lock_key), token in tokens.items():
|
||||
await self._drop_lock(lock_name, lock_key, token)
|
||||
|
||||
logger.info("Dropped locks due to shutdown")
|
||||
|
@ -98,3 +98,16 @@ class LockTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
lock2 = self.get_success(self.store.try_acquire_lock("name", "key"))
|
||||
self.assertIsNotNone(lock2)
|
||||
|
||||
def test_shutdown(self):
|
||||
"""Test that shutting down Synapse releases the locks"""
|
||||
# Acquire two locks
|
||||
lock = self.get_success(self.store.try_acquire_lock("name", "key1"))
|
||||
self.assertIsNotNone(lock)
|
||||
lock2 = self.get_success(self.store.try_acquire_lock("name", "key2"))
|
||||
self.assertIsNotNone(lock2)
|
||||
|
||||
# Now call the shutdown code
|
||||
self.get_success(self.store._on_shutdown())
|
||||
|
||||
self.assertEqual(self.store._live_tokens, {})
|
||||
|
Loading…
Reference in New Issue
Block a user