summary refs log tree commit diff
diff options
context:
space:
mode:
authorSean Quah <seanq@matrix.org>2022-09-07 20:37:09 +0100
committerSean Quah <seanq@matrix.org>2022-09-08 14:01:58 +0100
commit17dd4419a7af661cb637a8346ab0f31a5ac1ad2f (patch)
treed8d0ed85dfba52d8f74bea084495f0d16a9bd1cb
parentRemove redundant `mark_remote_user_device_list_as_unsubscribed` call (diff)
downloadsynapse-17dd4419a7af661cb637a8346ab0f31a5ac1ad2f.tar.xz
Check whether we still share a room when using cached device lists
Signed-off-by: Sean Quah <seanq@matrix.org>
-rw-r--r--synapse/handlers/e2e_keys.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/synapse/handlers/e2e_keys.py b/synapse/handlers/e2e_keys.py

index ec81639c78..9d97b7688b 100644 --- a/synapse/handlers/e2e_keys.py +++ b/synapse/handlers/e2e_keys.py
@@ -175,6 +175,33 @@ class E2eKeysHandler: user_ids_not_in_cache, remote_results, ) = await self.store.get_user_devices_from_cache(query_list) + + # Check that the homeserver still shares a room with all cached users. + # Note that this check may be slightly racy when a remote user leaves a + # room after we have fetched their cached device list. In the worst case + # we will do extra federation queries for devices that we had cached. + cached_users = set(remote_results.keys()) + valid_cached_users = ( + await self.store.get_users_server_still_shares_room_with( + remote_results.keys() + ) + ) + invalid_cached_users = cached_users - valid_cached_users + if invalid_cached_users: + # Fix up results. If we get here there may be bugs in device list + # tracking. + # TODO: is this actually useful? it doesn't fix the case where a + # remote user rejoins a room and we query their device list + # after. + user_ids_not_in_cache.update(invalid_cached_users) + for invalid_user_id in invalid_cached_users: + remote_results.pop(invalid_user_id) + logger.error( + "Devices for %s were cached, but the server no longer shares " + "any rooms with them. The cached device lists are stale.", + invalid_cached_users, + ) + for user_id, devices in remote_results.items(): user_devices = results.setdefault(user_id, {}) for device_id, device in devices.items():