Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix a rare bug where initial /syncs would fail #15383

Merged

Commits on Apr 3, 2023

  1. Fix an unlikely race where a room is un-partial stated during a /sync

    Signed-off-by: Sean Quah <seanq@matrix.org>
    Sean Quah committed Apr 3, 2023
    Configuration menu
    Copy the full SHA
    9e13e59 View commit details
    Browse the repository at this point in the history

Commits on Apr 4, 2023

  1. Fix a rare bug where initial /syncs would fail

    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 negative stream
        ordering, but higher topological ordering than the original user's
        leave. 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.
    
    Signed-off-by: Sean Quah <seanq@matrix.org>
    Sean Quah committed Apr 4, 2023
    Configuration menu
    Copy the full SHA
    b94f6d7 View commit details
    Browse the repository at this point in the history
  2. Add newsfile

    Sean Quah committed Apr 4, 2023
    Configuration menu
    Copy the full SHA
    896bc05 View commit details
    Browse the repository at this point in the history