anonymousland-synapse/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 Use mypy 1.0 (#15052) 2023-02-16 16:09:11 +00:00
__init__.py Remove redundant "coding: utf-8" lines (#9786) 2021-04-14 15:34:27 +01:00
account_data.py Experimental MSC3890 Implementation: Fix deleting account data when using an account data writer worker (#14869) 2023-03-03 10:51:57 +00:00
account_validity.py Move Account Validity callbacks to a dedicated file (#15237) 2023-03-16 10:35:31 +00:00
account.py Optionally include account validity in MSC3720 account status responses (#12266) 2022-03-24 11:19:41 +01:00
admin.py Add information on uploaded media to user export command. (#15107) 2023-02-23 13:14:17 -05:00
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 Fix twisted trunk mypy errors (#14012) 2022-10-03 13:26:49 +00:00
deactivate_account.py Add module API callbacks for adding and deleting local 3PID associations (#15044 2023-02-27 14:19:19 +00:00
device.py Revert pruning of old devices (#15360) 2023-03-31 13:51:51 +01:00
devicemessage.py Batch up replication requests to request the resyncing of remote users's devices. (#14716) 2023-01-10 11:17:59 +00:00
directory.py Bump black from 22.12.0 to 23.1.0 (#15103) 2023-02-22 15:29:09 -05:00
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 Bump black from 22.12.0 to 23.1.0 (#15103) 2023-02-22 15:29:09 -05:00
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_event.py Fix spinloop during partial state sync when a prev event is in backoff (#15351) 2023-03-30 13:36:41 +01: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
identity.py Refactor arguments of try_unbind_threepid(_with_id_server) from dict to separate args (#15053) 2023-02-13 12:12:48 +00:00
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 Use direct references for some configuration variables (part 3) (#10885) 2021-09-23 07:13:34 -04:00
presence.py Bump black from 22.12.0 to 23.1.0 (#15103) 2023-02-22 15:29:09 -05:00
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 Port the push rule classes to Rust. (#13768) 2022-09-20 12:10:31 +01:00
read_marker.py Refactor and convert Linearizer to async (#12357) 2022-04-05 15:43:52 +01:00
receipts.py Return read-only collections from @cached methods (#13755) 2023-02-10 23:29:00 +00:00
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_batch.py Batch up storing state groups when creating new room (#14918) 2023-02-24 13:15:29 -08:00
room_list.py Use stable prefixes for MSC3827: filtering of /publicRooms by room type (#13370) 2022-07-27 19:46:57 +01:00
room_member_worker.py Add support for knocking to workers. (#15133) 2023-03-02 12:59:53 -05:00
room_member.py Fix joining rooms you have been unbanned from (#15323) 2023-03-29 08:37:27 +00:00
room_summary.py Tweak comment on _is_local_room_accessible as part of room visibility in /hierarchy to clarify the condition for a room being visible. (#14834) 2023-02-13 16:30:58 +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
saml.py Remove redundant types from comments. (#14412) 2022-11-16 15:25:24 +00:00
search.py Pass the requester during event serialization. (#15174) 2023-03-06 16:08:39 +00:00
send_email.py Discourage automatic replies to Synapse's emails (#13957) 2022-09-30 13:23:37 +00:00
set_password.py Add a type hint for get_device_handler() and fix incorrect types. (#14055) 2022-11-22 14:08:04 -05:00
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 Remove HomeServer.get_datastore() (#12031) 2022-02-23 11:04:02 +00:00
stats.py Implement MSC3827: Filtering of /publicRooms by room type (#13031) 2022-06-29 17:12:45 +00:00
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