matterbridge: Matrix: having 5 bridged rooms results to M_LIMIT_EXCEEDED: Too Many Requests and failing bridge / potentially incompatible with Matrix Synapse 1.19.0

Describe the bug

I have 5 rooms that are bridged to Matrix. When I start matterbridge, it will fail to connect to Matrix due to

time="2020-08-20T07:24:39Z" level=error msg="Bridge matrix.feneas failed to join channel: contents=[123 34 101 114 114 99 111 100 101 34 58 34 77 95 76 73 77 73 84 95 69 88 67 69 69 68 69 68 34 44 34 101 114 114 111 114 34 58 34 84 111 111 32 77 97 110 121 32 82 101 113 117 101 115 116 115 34 44 34 114 101 116 114 121 95 97 102 116 101 114 95 109 115 34 58 57 55 50 56 125] msg=Failed to POST JSON to /_matrix/client/r0/join/!REDACTED:matrix.org code=429 wrapped=M_LIMIT_EXCEEDED: Too Many Requests" func=disableBridge file="gateway/router.go:111" prefix=router

I think this is related to homeserver having recently updated to Synapse 1.19.0

To Reproduce

  1. Configure 5 channels.
  2. Start matterbridge

Expected behavior

Matterbridge starts normally.

Screenshots/debug logs

time="2020-08-20T07:24:39Z" level=error msg="Bridge matrix.feneas failed to join channel: contents=[123 34 101 114 114 99 111 100 101 34 58 34 77 95 76 73 77 73 84 95 69 88 67 69 69 68 69 68 34 44 34 101 114 114 111 114 34 58 34 84 111 111 32 77 97 110 121 32 82 101 113 117 101 115 116 115 34 44 34 114 101 116 114 121 95 97 102 116 101 114 95 109 115 34 58 57 55 50 56 125] msg=Failed to POST JSON to /_matrix/client/r0/join/!REDACTED:matrix.org code=429 wrapped=M_LIMIT_EXCEEDED: Too Many Requests" func=disableBridge file="gateway/router.go:111" prefix=router

Environment (please complete the following information):

  • OS: Debian 9.13
  • Matterbridge version: 1.18.0 e3d8fe4f

Additional context

  • The homeserver was recently updated to Synapse 1.19.0
  • I don’t have config file on this machine, please ask if it’s really needed.
  • I think Matterbridge may be misbehaving by attempting to join the 5 rooms on start while you only need to join rooms once (unless you leave or get kicked), so it should just detect that it has joined those rooms already rather than trying to rejoin every start?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 21 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Sure and what about bots that haven’t joined rooms and need to join the rooms 😃 Those ratelimit defaults on matrix seem very strict, only 0.1 join per second allowed for the local rooms and 0.01 per second for remote rooms? that seems insane?

The idea is: On startup you fetch all joined rooms, so that you don’t attempt to re-join those rooms on startup

Then, when joining new rooms you just send the join there. Then, you handle M_LIMIT_EXCEEDED and re-try after the specified retry_after_ms plus like a second or so just to be sure? and then if you aren’t able to join after e.g. 5 tries or so you can consider it failed.

It also needs to join the rooms to get the id’s back to have the channel mapping.

there’s an API endpoint for that: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-joined-rooms

Would that be time.Sleep(10) ?

time.Sleep(10 * time.Second)

I also needed to add "time" to the import list at the top of the file. Hope this helps you work around it. (I doubt that this is really the correct fix; the bridge really should be able to detect the error and retry, but for a quick and dirty workaround it’s gotten my bridge back online.)