matrix-org / matrix-org/matrix-rust-sdk
`SpaceRoomList` apparently sends updates that cause duplicate entries
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.3k
- Forks
- 500
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 106
Description
A week ago we found out some crashes in Element X Android caused by duplicate entries in code, and we weren't sure where these were coming from, so we added some code to double check this by sending a custom error to Sentry and now we have some extra info.
We're seeing a few of these:
```
java.lang.IllegalStateException: Found duplicate keys in space rooms list ([!uNkmCFLIOYfYbGvVGz:fosdem.org, !vCQfjUPgoyATfYeXXJ:fosdem.org, !sueCBqsNfqsxtgCWNI:fosdem.org, !uzYwENEvmlcyLhwWal:fosdem.org])
After SDK updates: [PushBack(!oeWbgDVpESNzQNdNTb:fosdem.org), PushBack(!uNkmCFLIOYfYbGvVGz:fosdem.org), PushBack(!vCQfjUPgoyATfYeXXJ:fosdem.org), PushBack(!ayxmDawAxzSJxLgiEu:fosdem.org), PushBack(!rkZfhASlpQdOXiQYCc:fosdem.org), PushBack(!sueCBqsNfqsxtgCWNI:fosdem.org), PushBack(!eZcwZCAVaUtkWwFUpj:fosdem.org), PushBack(!uzYwENEvmlcyLhwWal:fosdem.org), PushBack(!cMgGiahHCUrxECyTpx:fosdem.org)]
```
This is found [in the code that's closer to the SDK listener](https://github.com/element-hq/element-x-android/blob/3ef5e76e99a23ef0ca9128c5b8d8944a49e6fb72/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/spaces/SpaceListUpdateProcessor.kt#L47) (`SpaceRoomListEntriesListener`), which takes the updates from the SDK and adds them to a channel with unlimited capacity (so no updates should be discarded), then this is processed in a method that has a Kotlin `Mutex` that should ensure a FIFO order in resumed coroutines, according to its docs. So unless we missed some detail, we're not discarding any updates and they are processed in order, and the code to modify the list based on the updates ([here](https://github.com/element-hq/element-x-android/blob/3ef5e76e99a23ef0ca9128c5b8d8944a49e6fb72/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/spaces/SpaceListUpdateProcessor.kt#L55)) seems fine, so we think this might be an issue in the SDK that's somehow rarely sending incorrect updates.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with SpaceListUpdateProcessor.kt, especially SpaceRoomListEntriesListener and the update-processing method linked in the report. Trace the SDK source of the updates and compare them with the Kotlin list mutations to determine where duplicate entries first appear. Done means identifying and correcting the incorrect update behavior, with a regression check for the reported duplicate-key case if the relevant test location is found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, rust
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100