matrix-org / matrix-appservice-discord

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

[M>D] 'M_USER_IN_USE' error; likely related to how matrix-bot-sdk handles registration checks #894

Closed msglm closed 10 months ago

msglm commented 10 months ago

Due to hacky fixes I have attempted to use while solving #864, I often end up having to go-through the install process of this program multiple times. This includes dropping the database entirely (before this hack was discovered as a temporary solution) and re-creating the appservice registration file. Because of these hacky fixes, matrix-appservice-discord often attempts to re-register the account used for bridging and reviving matrix commands on the homeserver. It fails at doing this and is unable to send messages or receive messages on either side. I could not find the line of code where this happens in the software itself, but the error that corresponds with it:

Aug-19 06:52:21.258 [bot-sdkMatrixHttpClient] error: [
  '(REQ-1)',
  { errcode: 'M_USER_IN_USE', error: 'User ID already taken.' }
]

Is the designated error that comes from ensuredRegistered() in matrix-bot-sdk. This implies that there is no handling for attempting to access the already-registered matrix-appservice-discord account on a homeserver (if such a thing is even possible).

This problem may be reproducible in more normal circumstances, such as migrating the location of a matrix-appservice-discord bot without migrating the database over, or in situations where a user desires to use a fork of this software.

Steps to reproduce:

  1. Follow the setup instructions until a proper bridge between discord and matrix is working
  2. Turn off the bridge
  3. Delete the databases related to matrix-discord-appservice
  4. remove the discord-registration.yaml file in both the homeserver and source code repo
  5. Follow the setup instructions again from the start
  6. Upon startup, matrix-discord-appservice should comment about a "M_USER_IN_USE" problem.

Hack workarounds: None Yet.

Possibly Related Issues:

840

835 (different bot library(?), same error)

37 (Old, possibly unrelated; same error however)

msglm commented 10 months ago

From my research, this bug seems to be caused by this line failing to return true. What causes this to be exact is not something I can figure out since I do not know javascript or the project itself too well.

msglm commented 10 months ago

Fixed the issue: If you're running Synapse 1.90 (and perhaps greater), you will need to enable legacy auth, since this project uses it. adding use_appservice_legacy_authorization: true to the matrix synapse server re-enables legacy auth. documentation on the subject: https://matrix-org.github.io/synapse/latest/upgrade#upgrading-to-v1900

MattyBoombalatty commented 8 months ago

I am having the same issue. I had to remake the discord-registration.yaml file but left the database untouched so I didn't have to re-bridge all of the rooms and now the messages come through fine, but they're not being displayed as the Discord user name in Matrix, just the tag set in the registration yaml file followed by a random set of numbers.