matrix-org / matrix-appservice-discord

A bridge between Matrix and Discord.
Apache License 2.0
790 stars 148 forks source link

Appservice crash loop with `Application service has not registered this user (@_discord_[…]:t2bot.io)` (while not on t2bot.io) #848

Closed pacien closed 1 year ago

pacien commented 1 year ago

I recently updated matrix-appservice-discord from v1.0.0 to v3.0.0. Everything worked for a while until the error in the log below. Since then, the bridge has been repeatedly crashing with the same error.

What's strange is that the error refers to an MXID ending with :t2bot.io while I'm hosting my own bridge and homeserver on my own domain. There's no reference to t2bot.io in my configuration.

Sep 15 10:44:17 h systemd[1]: Started A bridge between Matrix and Discord..
Sep 15 10:44:18 h matrix-appservice-discord[3272157]: Sep-15 10:44:18.758 [DiscordStore] info: Starting DB Init
Sep 15 10:44:18 h matrix-appservice-discord[3272157]: Sep-15 10:44:18.764 [DiscordStore] info: connString present in config, using postgres
Sep 15 10:44:18 h matrix-appservice-discord[3272157]: Sep-15 10:44:18.764 [Postgres] info: Opening socket:/run/postgresql?db=matrix-appservice-discord
Sep 15 10:44:18 h matrix-appservice-discord[3272157]: Sep-15 10:44:18.829 [DiscordStore] info: Database schema version is 12, latest version is 12
Sep 15 10:44:18 h matrix-appservice-discord[3272157]: Sep-15 10:44:18.829 [DiscordStore] info: Updated database to the latest schema
Sep 15 10:44:19 h matrix-appservice-discord[3272157]: Sep-15 10:44:19.712 [ClientFactory] info: Waiting for shardReady signal
Sep 15 10:44:19 h matrix-appservice-discord[3272157]: Sep-15 10:44:19.716 [ClientFactory] info: Got shardReady signal
Sep 15 10:44:19 h matrix-appservice-discord[3272157]: Sep-15 10:44:19.737 [DiscordBot] info: Discord bot client logged in.
Sep 15 10:44:19 h matrix-appservice-discord[3272157]: Sep-15 10:44:19.739 [DiscordAS] info: Discordbot started successfully
Sep 15 10:44:19 h matrix-appservice-discord[3272157]: Sep-15 10:44:19.753 [DiscordAS] info: Started listening on port 9005
Sep 15 10:52:49 h matrix-appservice-discord[3272157]: Sep-15 10:52:49.294 [bot-sdkAppservice] info: [ 'Processing transaction [REDACTED]' ]
Sep 15 10:52:49 h matrix-appservice-discord[3272157]: Sep-15 10:52:49.297 [bot-sdkAppservice] info: [ 'Processing event of type m.room.member' ]
Sep 15 10:52:49 h matrix-appservice-discord[3272157]: Sep-15 10:52:49.331 [bot-sdkMatrixHttpClient] error: [
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:   '(REQ-1)',
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:   {
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:     errcode: 'M_FORBIDDEN',
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:     error: 'Application service has not registered this user (@_discord_[REDACTED]:t2bot.io)'
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:   }
Sep 15 10:52:49 h matrix-appservice-discord[3272157]: ]
Sep 15 10:52:49 h matrix-appservice-discord[3272157]: /nix/store/hfg32xzcv1yx23yip4ssphdpm6x8pjaf-matrix-appservice-discord-3.0.0/libexec/matrix-appservice-discord/node_modules/matrix-bot-sdk/src/http.ts:110
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:         throw new MatrixError(errBody, response.statusCode);
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:               ^
Sep 15 10:52:49 h matrix-appservice-discord[3272157]: Error: M_FORBIDDEN: Application service has not registered this user (@_discord_[REDACTED]:t2bot.io)
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:     at doHttpRequest (/nix/store/hfg32xzcv1yx23yip4ssphdpm6x8pjaf-matrix-appservice-discord-3.0.0/libexec/matrix-appservice-discord/node_modules/matrix-bot-sdk/src/http.ts:110:15)
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:     at processTicksAndRejections (node:internal/process/task_queues:96:5)
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:     at MatrixClient.descriptor.value (/nix/store/hfg32xzcv1yx23yip4ssphdpm6x8pjaf-matrix-appservice-discord-3.0.0/libexec/matrix-appservice-discord/node_modules/matrix-bot-sdk/src/metrics/decorators.ts:28:32)
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:     at MatrixClient.descriptor.value (/nix/store/hfg32xzcv1yx23yip4ssphdpm6x8pjaf-matrix-appservice-discord-3.0.0/libexec/matrix-appservice-discord/node_modules/matrix-bot-sdk/src/metrics/decorators.ts:28:32)
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:     at Intent.refreshJoinedRooms (/nix/store/hfg32xzcv1yx23yip4ssphdpm6x8pjaf-matrix-appservice-discord-3.0.0/libexec/matrix-appservice-discord/node_modules/matrix-bot-sdk/src/appservice/Intent.ts:296:33)
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:     at Intent.descriptor.value (/nix/store/hfg32xzcv1yx23yip4ssphdpm6x8pjaf-matrix-appservice-discord-3.0.0/libexec/matrix-appservice-discord/node_modules/matrix-bot-sdk/src/metrics/decorators.ts:83:32)
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:     at Appservice.processMembershipEvent (/nix/store/hfg32xzcv1yx23yip4ssphdpm6x8pjaf-matrix-appservice-discord-3.0.0/libexec/matrix-appservice-discord/node_modules/matrix-bot-sdk/src/appservice/Appservice.ts:616:9)
Sep 15 10:52:49 h matrix-appservice-discord[3272157]:     at /nix/store/hfg32xzcv1yx23yip4ssphdpm6x8pjaf-matrix-appservice-discord-3.0.0/libexec/matrix-appservice-discord/node_modules/matrix-bot-sdk/src/appservice/Appservice.ts:841:21
Sep 15 10:52:49 h systemd[1]: matrix-appservice-discord.service: Main process exited, code=exited, status=1/FAILURE
Sep 15 10:52:49 h systemd[1]: matrix-appservice-discord.service: Failed with result 'exit-code'.
Half-Shot commented 1 year ago

What does your registration file look like (sans tokens)?

pacien commented 1 year ago

Here's the content of discord-registration.yaml:

id: REDACTED
hs_token: REDACTED
as_token: REDACTED
namespaces:
  users:
    - exclusive: true
      regex: '@_discord_.*'
  aliases:
    - exclusive: true
      regex: '#_discord_.*'
  rooms: []
url: 'http://localhost:9005'
sender_localpart: _discord_bot
rate_limited: false
protocols:
  - discord
Half-Shot commented 1 year ago

I'm not sure if a recent change broke it, but you need the domain of your homeserver on the end of those regex fields. E.g. @_discord_.*:half-shot.uk

pacien commented 1 year ago

Adding the homeserver to the regex(s) fixed the issue, thanks!

(This is quite strange nevertheless that it defaulted to t2bot.io; I couldn't find any reference to that domain in the source code).

Half-Shot commented 1 year ago

It just saw a t2bot in a room and thought "oh, that's one of mine!". Dumb bridge is dumb :p