mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 18:53:53 +01:00
Fix bug where we kept re-requesting a remote server's key repeatedly. (#16257)
* Correctly handle multiple rows per server/key * Newsfile
This commit is contained in:
parent
02bc5906ec
commit
c9cec2daed
2 changed files with 12 additions and 6 deletions
1
changelog.d/16257.bugfix
Normal file
1
changelog.d/16257.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix long-standing bug where we kept re-requesting a remote server's key repeatedly, potentially causing delays in receiving events over federation.
|
|
@ -221,12 +221,17 @@ class KeyStore(CacheInvalidationWorkerStore):
|
||||||
"""Processes a batch of keys to fetch, and adds the result to `keys`."""
|
"""Processes a batch of keys to fetch, and adds the result to `keys`."""
|
||||||
|
|
||||||
# batch_iter always returns tuples so it's safe to do len(batch)
|
# batch_iter always returns tuples so it's safe to do len(batch)
|
||||||
sql = """
|
where_clause = " OR (server_name=? AND key_id=?)" * len(batch)
|
||||||
SELECT server_name, key_id, key_json, ts_valid_until_ms
|
|
||||||
FROM server_keys_json WHERE 1=0
|
# `server_keys_json` can have multiple entries per server (one per
|
||||||
""" + " OR (server_name=? AND key_id=?)" * len(
|
# remote server we fetched from, if using perspectives). Order by
|
||||||
batch
|
# `ts_added_ms` so the most recently fetched one always wins.
|
||||||
)
|
sql = f"""
|
||||||
|
SELECT server_name, key_id, key_json, ts_valid_until_ms
|
||||||
|
FROM server_keys_json WHERE 1=0
|
||||||
|
{where_clause}
|
||||||
|
ORDER BY ts_added_ms
|
||||||
|
"""
|
||||||
|
|
||||||
txn.execute(sql, tuple(itertools.chain.from_iterable(batch)))
|
txn.execute(sql, tuple(itertools.chain.from_iterable(batch)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue