MatrixSynapse/synapse/handlers
Sean Quah 89a71e7390
Fix a rare bug where initial /syncs would fail (#15383)
This change fixes a rare bug where initial /syncs would fail with a
`KeyError` under the following circumstances:
 1. A user fast joins a remote room.
 2. The user is kicked from the room before the room's full state has
    been synced.
 3. A second local user fast joins the room.
 4. Events are backfilled into the room with a higher topological
    ordering than the original user's leave. They are assigned a
    negative stream ordering. It's not clear how backfill happened here,
    since it is expected to be equivalent to syncing the full state.
 5. The second local user leaves the room before the room's full state
    has been synced. The homeserver does not complete the sync.
 6. The original user performs an initial /sync with lazy_load_members
    enabled.
     * Because they were kicked from the room, the room is included in
       the /sync response even though the include_leave option is not
       specified.
     * To populate the room's timeline, `_load_filtered_recents` /
       `get_recent_events_for_room` fetches events with a lower stream
       ordering than the leave event and picks the ones with the highest
       topological orderings (which are most recent). This captures the
       backfilled events after the leave, since they have a negative
       stream ordering. These events are filtered out of the timeline,
       since the user was not in the room at the time and cannot view
       them. The sync code ends up with an empty timeline for the room
       that notably does not include the user's leave event.
       This seems buggy, but at least we don't disclose events the user
       isn't allowed to see.
     * Normally, `compute_state_delta` would fetch the state at the
       start and end of the room's timeline to generate the sync
       response. Since the timeline is empty, it fetches the state at
       `min(now, last event in the room)`, which corresponds with the
       second user's leave. The state during the entirety of the second
       user's membership does not include the membership for the first
       user because of partial state.
       This part is also questionable, since we are fetching state from
       outside the bounds of the user's membership.
     * `compute_state_delta` then tries and fails to find the user's
       membership in the auth events of timeline events. Because there
       is no timeline event whose auth events are expected to contain
       the user's membership, a `KeyError` is raised.

Also contains a drive-by fix for a separate unlikely race condition.

Signed-off-by: Sean Quah <seanq@matrix.org>
2023-04-04 13:10:25 +01:00
..
ui_auth
__init__.py
account.py
account_data.py
account_validity.py Move Account Validity callbacks to a dedicated file (#15237) 2023-03-16 10:35:31 +00:00
admin.py
appservice.py Implement MSC3984 to proxy /keys/query requests to appservices. (#15321) 2023-03-30 08:39:38 -04:00
auth.py Make cleaning up pushers depend on the device_id instead of the token_id (#15280) 2023-03-24 11:09:39 -04:00
cas.py
deactivate_account.py
device.py Revert pruning of old devices (#15360) 2023-03-31 13:51:51 +01:00
devicemessage.py
directory.py
e2e_keys.py Implement MSC3984 to proxy /keys/query requests to appservices. (#15321) 2023-03-30 08:39:38 -04:00
e2e_room_keys.py
event_auth.py More speedups/fixes to creating batched events (#15195) 2023-03-07 13:54:39 -08:00
events.py Make `EventHandler.get_event` return `None` when the requested event is not found (#15298) 2023-03-21 13:23:47 +00:00
federation.py Fix spinloop during partial state sync when a prev event is in backoff (#15351) 2023-03-30 13:36:41 +01:00
federation_event.py Fix spinloop during partial state sync when a prev event is in backoff (#15351) 2023-03-30 13:36:41 +01:00
identity.py
initial_sync.py Pass the requester during event serialization. (#15174) 2023-03-06 16:08:39 +00:00
message.py Fix error when sending message into deleted room. (#15235) 2023-03-21 09:13:43 +00:00
oidc.py Add the ability to enable/disable registrations when in the OIDC flow (#14978) 2023-03-30 11:09:41 +00:00
pagination.py Include the room ID in more purge room log lines. (#15222) 2023-03-08 20:08:56 +00:00
password_policy.py
presence.py
profile.py Refresh remote profiles that have been marked as stale, in order to fill the user directory. [rei:userdirpriv] (#14756) 2023-03-16 11:44:11 +00:00
push_rules.py
read_marker.py
receipts.py
register.py Revert pruning of old devices (#15360) 2023-03-31 13:51:51 +01:00
relations.py Pass the requester during event serialization. (#15174) 2023-03-06 16:08:39 +00:00
room.py Add topic and name events to group of events that are batch persisted when creating a room. (#15229) 2023-03-08 19:27:20 -08:00
room_batch.py
room_list.py
room_member.py Fix joining rooms you have been unbanned from (#15323) 2023-03-29 08:37:27 +00:00
room_member_worker.py
room_summary.py
saml.py
search.py Pass the requester during event serialization. (#15174) 2023-03-06 16:08:39 +00:00
send_email.py
set_password.py
sso.py Add the ability to enable/disable registrations when in the OIDC flow (#14978) 2023-03-30 11:09:41 +00:00
state_deltas.py
stats.py
sync.py Fix a rare bug where initial /syncs would fail (#15383) 2023-04-04 13:10:25 +01:00
typing.py Prune old typing notifications (#15332) 2023-03-27 14:32:36 +01:00
user_directory.py Refresh remote profiles that have been marked as stale, in order to fill the user directory. [rei:userdirpriv] (#14756) 2023-03-16 11:44:11 +00:00