element-hq / dendrite

Dendrite is a second-generation Matrix homeserver written in Go!
https://element-hq.github.io/dendrite/
GNU Affero General Public License v3.0
37 stars 6 forks source link

Some ghost user's memberships to bridge portals are missing in the dendrite database and thus said users messages are not bridged into the corresponding portal #3301

Open matrixbot opened 3 weeks ago

matrixbot commented 3 weeks ago

This issue was originally created by @mikewzr at https://github.com/matrix-org/dendrite/issues/3301.

Background information

Description

To be more specific: A user on telegram sends a message in a group. The telegram bridge tries to bridge the message to the matrix side but fails, as dendrite returns 403 "user does not belong to room" (as seen here).

I tried investigating the issue in the database an I found that the entry in roomserver_membership membership is missing. Curiously, the last event associated with the user and the room is the join event. Thus I tried to fixes this by adding the missing entry to roomserver_membership manually. This worked, but another check fails afterwards, as the join event is not associated with the roomserver_state_snapshot anymore. The bridge gets another 403 with the message "sender not in room". This is were I gave up, as there are hashes in the state related tables.

Steps to reproduce

Sadly I could not record when and how the ghost users get lost in the database, as I only notice the inconsistency when a message cannot be bridged anymore.

Workaround I found to get it up and running again (for telegram bridge at least)

The telegram bridge has its own database where it stores room memberships mx_user_profiles. When the entry for the ghost user and the corresponding room is deleted from this database, the telegram bridge thinks it has not added the user yet to the room. This way, when you use the sync command of the telegram bridge afterwards, the bridge re-adds the user to the room, which fixes the inconsistency in dendrite database.