matrix-org / sliding-sync

Proxy implementation of MSC3575's sync protocol.
https://github.com/matrix-org/matrix-spec-proposals/pull/3575
Apache License 2.0
239 stars 37 forks source link

Timeline reordering when run with multiple Synapse slow synchrotrons #215

Open kegsay opened 1 year ago

kegsay commented 1 year ago

This is a hypothetical problem and has not yet been seen in the wild.

The proxy relies on all pollers seeing the same set of events in the same order, and no poller can have seen event N without having seen N-1 first. This is not always true in reality: see #198. There is an edge case which can cause events to be inserted into the wrong place in the timeline. Consider:

All of the following need to happen for this to occur:

If the synchrotron is <50 events behind, then joining a room or repolling will fill in the timeline gap (due to the proxy asking for the max timeline limit of 50). If the slower synchrotron then delivers in a single sync response any one of those 50 events (e.g events [50+2, 50+1, 50] then we would ignore events [50+2, 50+1] due to taking the timeline positions into account (since #198).

The ramifications are unfortunately quite large, as the incorrectly positioned event could also affect the room state, not just the timeline.

kegsay commented 1 year ago

https://github.com/matrix-org/matrix-spec-proposals/pull/4033 would fix this as we can see event N-51 is older than N-50+.