Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix dropping locks on shut down (#10433)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston authored Jul 20, 2021
1 parent 96e63ec commit 54389d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/10433.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix error while dropping locks on shutdown. Introduced in v1.38.0.
6 changes: 5 additions & 1 deletion synapse/storage/databases/main/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ async def _on_shutdown(self) -> None:
"""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")
Expand Down
13 changes: 13 additions & 0 deletions tests/storage/databases/main/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,16 @@ def test_drop(self):

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, {})

0 comments on commit 54389d5

Please sign in to comment.