diff options
author | Sean Quah <8349537+squahtx@users.noreply.github.com> | 2022-09-14 10:42:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-14 10:42:57 +0100 |
commit | c73774467edb04c372caecb9e843542654f7610b (patch) | |
tree | b11058c6d1e62398929cbd970508e24b665d115e /synapse/storage | |
parent | Fix a long-standing spec compliance bug where Synapse would accept a trailing... (diff) | |
download | synapse-c73774467edb04c372caecb9e843542654f7610b.tar.xz |
Fix bug in device list caching when remote users leave rooms (#13749)
When a remote user leaves the last room shared with the homeserver, we have to mark their device list as unsubscribed, otherwise we would hold on to a stale device list in our cache. Crucially, the device list would remain cached even after the remote user rejoined the room, which could lead to E2EE failures until the next change to the remote user's device list. Fixes #13651. Signed-off-by: Sean Quah <seanq@matrix.org>
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/controllers/persist_events.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/synapse/storage/controllers/persist_events.py b/synapse/storage/controllers/persist_events.py index dad3731b9b..501dbbc990 100644 --- a/synapse/storage/controllers/persist_events.py +++ b/synapse/storage/controllers/persist_events.py @@ -598,9 +598,9 @@ class EventsPersistenceStorageController: # room state_delta_for_room: Dict[str, DeltaState] = {} - # Set of remote users which were in rooms the server has left. We - # should check if we still share any rooms and if not we mark their - # device lists as stale. + # Set of remote users which were in rooms the server has left or who may + # have left rooms the server is in. We should check if we still share any + # rooms and if not we mark their device lists as stale. potentially_left_users: Set[str] = set() if not backfilled: @@ -725,6 +725,20 @@ class EventsPersistenceStorageController: current_state = {} delta.no_longer_in_room = True + # Add all remote users that might have left rooms. + potentially_left_users.update( + user_id + for event_type, user_id in delta.to_delete + if event_type == EventTypes.Member + and not self.is_mine_id(user_id) + ) + potentially_left_users.update( + user_id + for event_type, user_id in delta.to_insert.keys() + if event_type == EventTypes.Member + and not self.is_mine_id(user_id) + ) + state_delta_for_room[room_id] = delta await self.persist_events_store._persist_events_and_state_updates( |