Skip to content

Leave request rejected for an invited user (race condition?) #20139

Description

@timofej673

Description

I have a bot on my_homeserver that rejects invitations from users who are not on the bot's whitelist by their Matrix ID.

Sometimes, from the perspective of the user on other_homeserver, the client does not show that the bot has rejected the invitation.

After further investigation, I found that this happens when the two homeservers end up in an inconsistent state: my_homeserver processes the invite rejection and considers the bot to have left the room, while other_homeserver rejects the corresponding leave event, resulting in an inconsistent room state between the two homeservers.

other_homeserver, where the client creates the room and invites the bot, rejects the leave event, claiming that the bot is not in the room, even though the bot has been invited to the room.

The logs also clearly show that the invitation was processed before the API request that created the room was completed.

This appears to be a race condition, as the issue does not occur consistently.

The client used on both instances is Cinny.

Steps to reproduce

  • Write a bot that quickly declines invitations (the bot runs on what I call "my homeserver").
  • Create a room on the remote homeserver and invite the bot to it at the same time using Cinny. You can do this by clicking "Create chat" in Direct Messages.
  • You may see similar logs.
  • The remote homeserver rejects the leave event; from the client's perspective, the bot does not appear to leave.

I expect the remote homeserver to accept and process the leave event, and the client to see the bot's leave event.

Homeserver

Both homeservers are private instances.

Synapse Version

My homeserver: {"server_version":"1.158.0"}, remote homeserver: {"server_version":"1.157.2"}

Installation Method

Docker (matrixdotorg/synapse)

Database

Database: My homeserver: PostgreSQL, one server. It was previously running on SQLite; the SQLite database was restored from a backup after it became corrupted, and the homeserver was later migrated to PostgreSQL. Remote homeserver: PostgreSQL, one server; it has always used PostgreSQL.

Workers

Single process

Platform

My homeserver: Arch Linux, bare metal
Other homeserver: Ubuntu 26.04 LTS (Resolute Raccoon), running in an LXC container

Configuration

presence disabled on remote homeserver

Relevant log output

I'll put the two logs in a separate section for easier viewing.

Anything else that would be useful to know?

All homeservers are running the official Docker image.

Logs from my homeserver:

synapse-1 | 2026-08-24 17:49:40,487 - synapse.access.http.8008 - 643 - INFO - PUT-9408 - <redacted> - 8008 - {<other_homeserver>} Processed request: 0.077sec/0.002sec ru=(0.012sec, 0.001sec) db=(0.006sec/0.023sec/11) 886B 200 "PUT /_matrix /federation/v2/invite/%21AltPCbAnqTbCyNrVzG%3A<other_homeserver>/%24TdxxX4gt8CGgj4NYDv9YEEDNR_1MhaeeUvgxn3sxqBo HTTP/1.1" "Synapse/1.157.2" [0 dbevts] 
synapse-1 | 2026-08-24 17:49:40,490 - synapse.handlers.sync - 1949 - INFO - GET-9402 - User membership change between getting rooms and current token: @bot:<my_homeserver> invite !AltPCbAnqTbCyNrVzG:<other_homeserver> 
synapse-1 | 2026-08-24 17:49:40,495 - synapse.storage.controllers.state - 467 - INFO - GET-9402 - Failed to find any events in room !AltPCbAnqTbCyNrVzG:<other_homeserver> at RoomStreamToken(stream: 888030, topological: None, instances: {}) 
synapse-1 | 2026-08-24 17:49:40,497 - synapse.access.http.8008 - 643 - INFO - GET-9402 - 192.168.1.1 - 8008 - {@bot:<my_homeserver>} Processed request: 8.501sec/0.001sec ru=(0.007sec, 0.000sec) db=(0.003s ec/0.005sec/3) 971B 200 "GET /_matrix/client/v3/sync?access_token=<redacted>&since=<redacted>&full_state=false&timeout=30000&filter=%7B%22account_data%22%3A%7B%22types%22%3A%5B%5D%7D%2C%22pr esence%22%3A%7B%22types%22%3A%5B%5D%7D%2C%22room%22%3A%7B%22account_data%22%3A%7B%22types%22%3A%5B%5D%7D%2C%22ephemeral%22%3A%7B%22types%22%3A%5B%5D%7D%2C%22state%22%3A%7B%22types%22%3A%5B%22m.room.member%22%5D%7D%2C%22timeline%22%3A%7B%2 2types%22%3A%5B%22m.room.message%22%5D%2C%22limit%22%3A20%7D%7D%7D HTTP/1.1" "nio" [0 dbevts] 
synapse-1 | 2026-08-24 17:49:40,510 - synapse.handlers.room_member - 1157 - INFO - POST-9409 - @bot:<my_homeserver> rejects invite to !AltPCbAnqTbCyNrVzG:<other_homeserver> from @timofej:<other_homeserver> 
synapse-1 | 2026-08-24 17:49:40,647 - synapse.http.matrixfederationclient - 793 - INFO - POST-9409 - {GET-O-1026} [<other_homeserver>] Got response headers: 403 Forbidden 
synapse-1 | 2026-08-24 17:49:40,648 - synapse.http.matrixfederationclient - 894 - WARNING - POST-9409 - {GET-O-1026} [<other_homeserver>] Request failed: GET matrix-federation://<other_homeserver>/_matrix/federation/v1/make_leave/%21AltPCbAnqTbCyNrVzG%3A<other_homeserver>/%40bot%3A<my_homeserver>: HttpResponseException('403: Forbidden') 
synapse-1 | 2026-08-24 17:49:40,649 - synapse.handlers.room_member - 2064 - WARNING - POST-9409 - Failed to reject invite: 403: @bot:<my_homeserver> not in room !AltPCbAnqTbCyNrVzG:<other_homeserver>.
synapse-1 | 2026-08-24 17:49:40,696 - synapse.access.http.8008 - 643 - INFO - POST-9409 - 192.168.1.1 - 8008 - {@bot:<my_homeserver>} Processed request: 0.196sec/0.000sec ru=(0.014sec, 0.000sec) db=(0.002 sec/0.008sec/7) 2B 200 "POST /_matrix/client/v3/rooms/%21AltPCbAnqTbCyNrVzG%3A<other_homeserver>/leave?access_token=<redacted> HTTP/1.1" "nio" [0 dbevts]

Logs from remote homeserver:

synapse-1 | 2026-08-24 17:49:39,461 - synapse.handlers.sync - 1949 - INFO - GET-56643 - User membership change between getting rooms and current token: @timofej:<other_homeserver> join !AltPCbAnqTbCyNrVzG:<other_homeserver> 
synapse-1 | 2026-08-24 17:49:39,469 - synapse.federation.sender - 649 - INFO - process_event_queue_for_federation-6439 - Unexpectedly did not have cached prev group for $MNjgkJxkFWkzwzrILi1DQQJDjQtPjFhd_NbknpSpjEE 
synapse-1 | 2026-08-24 17:49:39,531 - synapse.storage.controllers.state - 467 - INFO - GET-56643 - Failed to find any events in room !AltPCbAnqTbCyNrVzG:<other_homeserver> at RoomStreamToken(stream: 937262, topological: None, instances: {}) 
synapse-1 | 2026-08-24 17:49:39,641 - synapse.access.http.8008 - 643 - INFO - GET-56643 - unix: - 8008 - {@timofej:<other_homeserver>} Processed request: 17.133sec/0.001sec ru=(0.018sec, 0.009sec) db=(0.017sec/0.080sec/15) 1827B 200 "GET /_matrix/client/v3/sync?filter=0&timeout=30000&org.matrix.msc4222.use_state_after=true&since=<redacted> HTTP/1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:154.0) Gecko/20100101 Firefox/154.0" [0 dbevts] 
synapse-1 | 2026-08-24 17:49:39,752 - synapse.access.http.8008 - 643 - INFO - POST-56652 - unix: - 8008 - {@timofej:<other_homeserver>} Processed request: 0.011sec/0.009sec ru=(0.003sec, 0.001sec) db=(0.000sec/0.006sec/2) 2 642B 200 "POST /_matrix/client/v3/keys/query HTTP/1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:154.0) Gecko/20100101 Firefox/154.0" [0 dbevts] 
synapse-1 | 2026-08-24 17:49:39,935 - synapse.federation.sender - 649 - INFO - process_event_queue_for_federation-6440 - Unexpectedly did not have cached prev group for $ot2GYOic2WJBhLnE-9rX5cQlNU2XSQQQrgUf0PGMyYc 
synapse-1 | 2026-08-24 17:49:39,948 - synapse.federation.sender - 649 - INFO - process_event_queue_for_federation-6440 - Unexpectedly did not have cached prev group for $mbzMXNXYp9Dd8-iU_jIdq9P7Kj6vb7uzWPr2G7sMLKI 
synapse-1 | 2026-08-24 17:49:39,958 - synapse.federation.sender - 649 - INFO - process_event_queue_for_federation-6440 - Unexpectedly did not have cached prev group for $TiMN19VC68d0nUGCgzq-2X2CUkfLaC_wfAQgwqBjedI 
synapse-1 | 2026-08-24 17:49:39,967 - synapse.federation.sender - 649 - INFO - process_event_queue_for_federation-6440 - Unexpectedly did not have cached prev group for $vEE_Pv67H3Ym7YAZvauHDHOV4gCsupT-rcxjSWdpW9w 
synapse-1 | 2026-08-24 17:49:40,060 - synapse.http.matrixfederationclient - 371 - INFO - POST-56648 - {GET-O-30221} [<my_homeserver>] Completed request: 200 OK in 0.16 secs, got 27 bytes - GET matrix-federation://<my_homeserver>/_matrix/federation/v1/query/profile?user_id=%40bot%3A<my_homeserver>&field=displayname 
synapse-1 | 2026-08-24 17:49:40,099 - synapse.access.http.8008 - 643 - INFO - GET-56651 - unix: - 8008 - {@timofej:<other_homeserver>} Processed request: 0.370sec/0.001sec ru=(0.014sec, 0.003sec) db=(0.013sec/0.176sec/7) 31 80B 200 "GET /_matrix/client/v3/sync?filter=0&timeout=30000&org.matrix.msc4222.use_state_after=true&since=<redacted> HTTP/1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:154.0) Gecko/20100101 Firefox/154.0" [0 dbevts] 
synapse-1 | 2026-08-24 17:49:40,165 - synapse.http.matrixfederationclient - 371 - INFO - POST-56648 - {GET-O-30222} [<my_homeserver>] Completed request: 200 OK in 0.10 secs, got 2 bytes - GET matrix-federation://<my_homeserver>/_matrix/federation/v1/query/profile?user_id=%40bot%3A<my_homeserver>&field=avatar_url synapse-1 | 2026-08-24 17:49:40,572 - synapse.http.matrixfederationclient - 371 - INFO - POST-56648 - {PUT-O-30223} [<my_homeserver>] Completed request: 200 OK in 0.29 secs, got 886 bytes - PUT matrix-federation://<my_homeserver>/_matrix/federation/v2/invite/%21AltPCbAnqTbCyNrVzG%3A<other_homeserver>/%24TdxxX4gt8CGgj4NYDv9YEEDNR_1MhaeeUvgxn3sxqBo 
synapse-1 | 2026-08-24 17:49:40,632 - synapse.handlers.federation - 1307 - WARNING - GET-56655 - Failed to create new leave <Event event_id=$G4z66-5Aaml8Pz41EQsCgB17FL_1qDnyD4sB5W9l81w, type=m.room.member, state_key=@ bot:<my_homeserver, membership=leave> because 403: @bot:<my_homeserver> not in room !AltPCbAnqTbCyNrVzG:<other_homeserver>. 
synapse-1 | 2026-08-24 17:49:40,632 - synapse.http.server - 132 - INFO - GET-56655 - <XForwardedForRequest at 0x728de79cd810 method='GET' uri='/_matrix/federation/v1/make_leave/%21AltPCbAnqTbCyNrVzG%3A<other_homeserver>/%40 bot%3A<my_homeserver>' clientproto='HTTP/1.1' site='8008'> SynapseError: 403 - @bot:<my_homeserver> not in room !AltPCbAnqTbCyNrVzG:<other_homeserver>. 
synapse-1 | 2026-08-24 17:49:40,636 - synapse.access.http.8008 - 643 - INFO - GET-56655 - unix: - 8008 - {<my_homeserver>} Processed request: 0.031sec/0.001sec ru=(0.007sec, 0.001sec) db=(0.004sec/0.012sec/4) 109B 40 3 "GET /_matrix/federation/v1/make_leave/%21AltPCbAnqTbCyNrVzG%3A<other_homeserver>/%40bot%3A<my_homeserver> HTTP/1.1" "Synapse/1.158.0" [0 dbevts] 
synapse-1 | 2026-08-24 17:49:40,701 - synapse.access.http.8008 - 643 - INFO - POST-56648 - unix: - 8008 - {@timofej:<other_homeserver>} Processed request: 1.639sec/0.009sec ru=(0.091sec, 0.017sec) db=(0.040sec/0.194sec/35) 46B 200 "POST /_matrix/client/v3/createRoom HTTP/1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:154.0) Gecko/20100101 Firefox/154.0" [0 dbevts]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions