This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
Huge database queries from POST /_matrix/client/v3/keys/query
#13580
Labels
A-Database
DB stuff like queries, migrations, new/remove columns, indexes, unexpected entries in the db
O-Frequent
Affects or can be seen by most users regularly or impacts most users' first experience
S-Major
Major functionality / product severely impaired, no satisfactory workaround.
T-Defect
Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
We frequently see a rapid sequence of calls to
POST /_matrix/client/v3/keys/query
from a single device (usually Element/iOS, afaict from eyeballing the logs).Each request typically contain queries for a large number of user ids (like, tens of thousands), of which many/most can be on the local server. We then translate that into a single
SELECT
query ondevices
ande2e_device_keys_json
with a hugeWHERE
clause (here). This can then consume vast amounts of disk space on the database server, because it logs the query thousands of times (it creates many temporary files, and the query is logged each time).There are several easy improvements to be made here:
IN
query rather than a huge list of(user_id = foo) OR (user_id = bar)
. This is more complicated than normal because we need to query onuser_id
anddevice_id
, however I believe that postgres at least supportsIN
for tuples. It's more complicated still because we may have a mix of queries, some which match onlyuser_id
and some which match bothuser_id
anddevice_id
, so we may need to split the query list in two.devices
at all. AFAICT the only thing that we pull out of it is thedisplay_name
, which is not in the spec forPOST /_matrix/client/v3/keys/query
(though it is mentioned in the examples and currently returned in practice. Still, I don't think we should return other peoples' device display names here.) Related: Device names are returned over federation by/keys/query
even ifallow_device_name_lookup_over_federation
is false #13114, which discusses this further.The text was updated successfully, but these errors were encountered: