element-hq / element-hq/dendrite
UNIQUE constraint failed: syncapi_account_data_type.id
- Dominant language
- Go
- Stars
- 965
- Forks
- 101
- PR merge metrics
- No merged PRs in 30d
Description
*This issue was originally created by [**@bodqhrohro**](https://github.com/bodqhrohro) at .*
### Background information
- **Dendrite version or git SHA**: d6e9b7b307ff0d7541046ec33890d49239c7a6ca
- **Monolith or Polylith?**: Monolith
- **SQLite3 or Postgres?**: SQLite3
- **Running in Docker?**: no
- **`go version`**: go1.15.2 linux/amd64
### Description
Occasionally Dendrite began to panic at the start:
```
PANI[2021-04-27T22:40:21.434099834Z] [/media/d/temp/git/dendrite/syncapi/consumers/clientapi.go:100] onMessage
could not save account data error="UNIQUE constraint failed: syncapi_account_data_type.id" room_id="!udNJiNGkemsobJTe:localhost" type=m.fully_read
panic: (*logrus.Entry) 0xc0001e1960
goroutine 114 [running]:
github.com/sirupsen/logrus.(*Entry).log(0xc0001e1880, 0x0, 0xc00049ed40, 0x1b)
/opt/gone/pkg/mod/github.com/sirupsen/logrus@v1.8.0/entry.go:259 +0x2e5
github.com/sirupsen/logrus.(*Entry).Log(0xc0001e1880, 0x0, 0xc0002dbaf8, 0x1, 0x1)
/opt/gone/pkg/mod/github.com/sirupsen/logrus@v1.8.0/entry.go:285 +0x86
github.com/sirupsen/logrus.(*Entry).Logf(0xc0001e1880, 0xc000000000, 0x1219428, 0x1b, 0x0, 0x0, 0x0)
/opt/gone/pkg/mod/github.com/sirupsen/logrus@v1.8.0/entry.go:330 +0xe5
github.com/sirupsen/logrus.(*Entry).Panicf(...)
/opt/gone/pkg/mod/github.com/sirupsen/logrus@v1.8.0/entry.go:368
github.com/matrix-org/dendrite/syncapi/consumers.(*OutputClientDataConsumer).onMessage(0xc0004892f0, 0xc000238320, 0x1, 0x101)
/media/d/temp/git/dendrite/syncapi/consumers/clientapi.go:100 +0x785
github.com/matrix-org/dendrite/internal.(*ContinualConsumer).consumePartition(0xc000429140, 0x13a3760, 0xc0002b5f60)
/media/d/temp/git/dendrite/internal/consumers.go:126 +0xe2
created by github.com/matrix-org/dendrite/internal.(*ContinualConsumer).StartOffsets
/media/d/temp/git/dendrite/internal/consumers.go:107 +0x545
```
### Steps to reproduce
Unfortunately, I don't know exactly how did this happen. My `syncapi_account_data_type` table had ids `11 12 46 47 61 91 401 405 407 444 449`, and the `syncapi_stream_id` table was:
```
@sqlite> select * from syncapi_stream_id;
global|475
receipt|5
accountdata|11
invite|0
```
Thus `nextAccountDataID` generated an already existing `12` id, instead of something unique. So the database had to be manually fixed by executing `update syncapi_stream_id set stream_id=450 where stream_name="accountdata";`
Contributor guide
Research direction
Start in syncapi/consumers/clientapi.go at OutputClientDataConsumer.onMessage and trace the nextAccountDataID path that writes syncapi_account_data_type and syncapi_stream_id. Inspect how the accountdata stream ID is advanced, then verify that startup and account-data processing cannot generate an existing ID; the issue provides no reproduction test or named test file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sqlite
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100