element-hq / element-hq/synapse
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "e2e_one_time_keys_json_uniqueness"
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
This issue has been migrated from [#7365](https://github.com/matrix-org/synapse/issues/7365).
---
Storage function `add_e2e_one_time_keys` claims that it raises an error when one tries to insert a key that already exists in the db. This makes a call to `/keys/upload` fail if one of the keys in the set is already known:
```
synapse.http.server - 110 - ERROR - POST-xxx - Failed handle request via 'KeyUploadServlet':
...
File "/synapse/storage/data_stores/main/end_to_end_keys.py", line 237, in _add_e2e_one_time_keys
for algorithm, key_id, json_bytes in new_keys
File "/synapse/storage/database.py", line 684, in simple_insert_many_txn
txn.executemany(sql, vals)
File "/synapse/storage/database.py", line 202, in executemany
self._do_execute(self.txn.executemany, sql, *args)
File "/synapse/storage/database.py", line 225, in _do_execute
return func(sql, *args)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "e2e_one_time_keys_json_uniqueness"
DETAIL: Key (user_id, device_id, algorithm, key_id)=(@blabla:example.com, ATNXJDJWK, signed_curve25519, AAAANR) already exists.
```
Perhaps this in intentional, but presumably we'd want to just skip a key if we already have it and continue inserting the rest rather than 500 (well, ideally we wouldn't do that in any case).
Contributor guide
Assessment
This issue has not been assessed yet.