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.
This commit is contained in:
Erik Johnston 2024-02-09 10:51:11 +00:00 committed by GitHub
parent 7c805f00a7
commit bfa93d1d3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

1
changelog.d/16894.bugfix Normal file
View File

@ -0,0 +1 @@
Do not send multiple concurrent requests for keys for the same server.

View File

@ -839,11 +839,12 @@ class ServerKeyFetcher(BaseV2KeyFetcher):
Map from server_name -> key_id -> FetchKeyResult Map from server_name -> key_id -> FetchKeyResult
""" """
# We only need to do one request per server.
servers_to_fetch = {k.server_name for k in keys_to_fetch}
results = {} results = {}
async def get_keys(key_to_fetch_item: _FetchKeyRequest) -> None: async def get_keys(server_name: str) -> None:
server_name = key_to_fetch_item.server_name
try: try:
keys = await self.get_server_verify_keys_v2_direct(server_name) keys = await self.get_server_verify_keys_v2_direct(server_name)
results[server_name] = keys results[server_name] = keys
@ -852,7 +853,7 @@ class ServerKeyFetcher(BaseV2KeyFetcher):
except Exception: except Exception:
logger.exception("Error getting keys from %s", server_name) 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 return results
async def get_server_verify_keys_v2_direct( async def get_server_verify_keys_v2_direct(