mautrix / discord

A Matrix-Discord puppeting bridge
https://go.mau.fi/mautrix-discord
GNU Affero General Public License v3.0
240 stars 22 forks source link

`bridge --entire` + `restricted_rooms: true` results in invalid `join_rules` sent to server #151

Closed ToxicFrog closed 1 month ago

ToxicFrog commented 1 month ago

I haven't figured out what the root cause of this is, but when M-D is creating large numbers of channels at once (for example, when you bridge a large discord -- 30+ channels -- using --entire), at some point it starts sending join_rules that look like this:

{
    "content": {
        "allow": [ { "room_id": "", "type": "m.room_membership" } ],
        "join_rule": "restricted"
    },
    "type": "m.room.join_rules"
}

for leaf channels. The room_id field there is meant to be the ID of the enclosing space -- since restricted_rooms is set -- but instead it is blank, which means not only does it not do what's intended, it isn't even well-formed.

Per the spec, the Matrix server is meant to interpret this as the created channel being invite-only. I don't know if M-D properly handles this mismatch between its expectations and actual behaviour, however, because this also triggers a bug in current versions of Conduit that renders the created channel entirely nonfunctional, making further investigation difficult.

I suspect (but have not really investigated) that this is some sort of race condition in the appservice, since it seems to happen only when asking for large numbers of bridges to be created at once; on-demand bridging did not exhibit this problem, or if it did, did so so rarely that I didn't notice the occasional channel not being created here and there.

ToxicFrog commented 1 month ago

Testing it without restricted_rooms, I note that a majority of channels created, when creating portal channels in bulk, are not properly placed inside the Discord space and just left lying around; that may have the same root cause, just with a more benign expression.