matrix-org / matrix-org/matrix-rust-sdk

`SpaceRoomList` apparently sends updates that cause duplicate entries

Open
#6,042 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.