diff --git a/changelog.d/16894.bugfix b/changelog.d/16894.bugfix new file mode 100644 index 00000000000..7e05370be7a --- /dev/null +++ b/changelog.d/16894.bugfix @@ -0,0 +1 @@ +Do not send multiple concurrent requests for keys for the same server. diff --git a/synapse/crypto/keyring.py b/synapse/crypto/keyring.py index 1e7e5f70fef..8c301e077c2 100644 --- a/synapse/crypto/keyring.py +++ b/synapse/crypto/keyring.py @@ -839,11 +839,12 @@ async def _fetch_keys( Map from server_name -> key_id -> FetchKeyResult """ - results = {} + # We only need to do one request per server. + servers_to_fetch = {k.server_name for k in keys_to_fetch} - async def get_keys(key_to_fetch_item: _FetchKeyRequest) -> None: - server_name = key_to_fetch_item.server_name + results = {} + async def get_keys(server_name: str) -> None: try: keys = await self.get_server_verify_keys_v2_direct(server_name) results[server_name] = keys @@ -852,7 +853,7 @@ async def get_keys(key_to_fetch_item: _FetchKeyRequest) -> None: except Exception: logger.exception("Error getting keys from %s", server_name) - await yieldable_gather_results(get_keys, keys_to_fetch) + await yieldable_gather_results(get_keys, servers_to_fetch) return results async def get_server_verify_keys_v2_direct(