element-hq / element-hq/dendrite

E2E room keys table duplicate error

Open
#2,095 0 comments 0 reactions 0 assignees View on GitHub
C-User-API F-E2EE T-Defect
Dominant language
Go
Stars
965
Forks
101
PR merge metrics
No merged PRs in 30d

Description

*This issue was originally created by [**@kegsay**](https://github.com/kegsay) at .*

```
an 15 03:57:49 matrix postgres[22977]: 2022-01-15 03:57:49.886 UTC [22977] ERROR: duplicate key value violates unique constraint "e2e_room_keys_idx"
Jan 15 03:57:49 matrix postgres[22977]: 2022-01-15 03:57:49.886 UTC [22977] DETAIL: Key (user_id, room_id, session_id, version)=(@real-changeling:hisp>
Jan 15 03:57:49 matrix postgres[22977]: 2022-01-15 03:57:49.886 UTC [22977] STATEMENT: INSERT INTO account_e2e_room_keys(user_id, room_id, session_id,>
Notice: journal has been rotated since unit was started, output may be incomplete.
```

For table:
```sql
CREATE TABLE IF NOT EXISTS account_e2e_room_keys (
user_id TEXT NOT NULL,
room_id TEXT NOT NULL,
session_id TEXT NOT NULL,

version TEXT NOT NULL,
first_message_index INTEGER NOT NULL,
forwarded_count INTEGER NOT NULL,
is_verified BOOLEAN NOT NULL,
session_data TEXT NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS e2e_room_keys_idx ON account_e2e_room_keys(user_id, room_id, session_id, version);
CREATE INDEX IF NOT EXISTS e2e_room_keys_versions_idx ON account_e2e_room_keys(user_id, version);
```

So in other words the client is uploading the same key backup twice. This is probably possible if there are network errors on the request to upload keys. Feels like an easy fix with a Complement regression test.

Contributor guide

Open the contributing guide

Research direction

Start with the account_e2e_room_keys schema and the end-to-end key-upload path, then reproduce the duplicate upload with a Complement regression test. Done means retrying the same key upload no longer causes the e2e_room_keys_idx duplicate-key error and the regression test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.