diff options
author | Erik Johnston <erikj@element.io> | 2024-02-09 10:51:11 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-09 10:51:11 +0000 |
commit | bfa93d1d3ba880244cbb8e8420832db1563bf6c3 (patch) | |
tree | 83601f94c213ed223c9d5344f2110a3f8c8896e6 /synapse | |
parent | 1.101.0rc1 (diff) | |
download | synapse-bfa93d1d3ba880244cbb8e8420832db1563bf6c3.tar.xz |
Only do one concurrent fetch per server in keyring (#16894)
Otherwise if we've stacked a bunch of requests for the keys of a server, we'll end up sending lots of concurrent requests for its keys, needlessly.
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/crypto/keyring.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/synapse/crypto/keyring.py b/synapse/crypto/keyring.py index 1e7e5f70fe..8c301e077c 100644 --- a/synapse/crypto/keyring.py +++ b/synapse/crypto/keyring.py @@ -839,11 +839,12 @@ class ServerKeyFetcher(BaseV2KeyFetcher): 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 @@ class ServerKeyFetcher(BaseV2KeyFetcher): 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( |