forked-synapse/synapse
Eric Eastwood fa8616e65c
Fix MSC3030 /timestamp_to_event returning outliers that it has no idea whether are near a gap or not (#14215)
Fix MSC3030 `/timestamp_to_event` endpoint returning `outliers` that it has no idea whether are near a gap or not (and therefore unable to determine whether it's actually the closest event). The reason Synapse doesn't know whether an `outlier` is next to a gap is because our gap checks rely on entries in the `event_edges`, `event_forward_extremeties`, and `event_backward_extremities` tables which is [not the case for `outliers`](2c63cdcc3f/docs/development/room-dag-concepts.md (outliers)).

Also fixes MSC3030 Complement `can_paginate_after_getting_remote_event_from_timestamp_to_event_endpoint` test flake.  Although this acted flakey in Complement, if `sync_partial_state` raced and beat us before `/timestamp_to_event`, then even if we retried the failing `/context` request it wouldn't work until we made this Synapse change. With this PR, Synapse will never return an `outlier` event so that test will always go and ask over federation.

Fix  https://github.com/matrix-org/synapse/issues/13944


### Why did this fail before? Why was it flakey?

Sleuthing the server logs on the [CI failure](https://github.com/matrix-org/synapse/actions/runs/3149623842/jobs/5121449357#step:5:5805), it looks like `hs2:/timestamp_to_event` found `$NP6-oU7mIFVyhtKfGvfrEQX949hQX-T-gvuauG6eurU` as an `outlier` event locally. Then when we went and asked for it via `/context`, since it's an `outlier`, it was filtered out of the results -> `You don't have permission to access that event.`

This is reproducible when `sync_partial_state` races and persists `$NP6-oU7mIFVyhtKfGvfrEQX949hQX-T-gvuauG6eurU` as an `outlier` before we evaluate `get_event_for_timestamp(...)`. To consistently reproduce locally, just add a delay at the [start of `get_event_for_timestamp(...)`](cb20b885cb/synapse/handlers/room.py (L1470-L1496)) so it always runs after `sync_partial_state` completes.

```py
from twisted.internet import task as twisted_task
d = twisted_task.deferLater(self.hs.get_reactor(), 3.5)
await d
```

In a run where it passes, on `hs2`, `get_event_for_timestamp(...)` finds a different event locally which is next to a gap and we request from a closer one from `hs1` which gets backfilled. And since the backfilled event is not an `outlier`, it's returned as expected during `/context`.

With this PR, Synapse will never return an `outlier` event so that test will always go and ask over federation.
2022-10-18 19:46:25 -05:00
..
_scripts Add an API for listing threads in a room. (#13394) 2022-10-13 08:02:11 -04:00
api Support filtering the /messages API by relation type (MSC3874). (#14148) 2022-10-17 11:32:11 -04:00
app Mark /relations endpoint as usable on workers. (#14028) 2022-10-12 06:46:13 -04:00
appservice Send the appservice access token as a header. (#13996) 2022-10-04 07:06:41 -04:00
config Implementation of HTTP 307 response for MSC3886 POST endpoint (#14018) 2022-10-18 15:52:25 +00:00
crypto Instrument _check_sigs_and_hash_and_fetch to trace time spent in child concurrent calls (#13588) 2022-08-23 21:53:37 -05:00
events Fix docstring in EventContext (#14145) 2022-10-18 13:40:50 -07:00
federation Don't require optional invite_room_state field on fed v2 invite (#14083) 2022-10-14 13:48:33 +01:00
handlers Prepatory work for adding power level event to batched events (#14214) 2022-10-18 09:58:47 -07:00
http Implementation of HTTP 307 response for MSC3886 POST endpoint (#14018) 2022-10-18 15:52:25 +00:00
logging Update mypy and mypy-zope, attempt 3 (#13993) 2022-09-30 17:36:28 +01:00
metrics Catch BrokenPipeError from metrics server, and log as a warning (#14072) 2022-10-07 13:35:44 +01:00
module_api Deprecate the generate_short_term_login_token method in favor of an async create_login_token method in the Module API. (#13842) 2022-10-06 10:22:36 +00:00
push Return the main timeline for events which are not part of a thread. (#14140) 2022-10-12 12:15:52 -04:00
replication Merge remote-tracking branch 'origin/release-v1.69' into develop 2022-10-14 14:11:27 -04:00
res Add viewport directive to HTML templates to optimise for mobile (#13493) 2022-08-11 14:04:20 +01:00
rest Implementation of HTTP 307 response for MSC3886 POST endpoint (#14018) 2022-10-18 15:52:25 +00:00
server_notices Directly lookup local membership instead of getting all members in a room first (get_users_in_room mis-use) (#13608) 2022-08-24 14:13:12 -05:00
spam_checker_api Fix import in module_api module and docs on the new check_event_for_spam signature (#12918) 2022-05-31 12:04:53 +02:00
state Prepatory work for batching events to send (#13487) 2022-09-28 10:39:03 +01:00
static Add viewport directive to HTML templates to optimise for mobile (#13493) 2022-08-11 14:04:20 +01:00
storage Fix MSC3030 /timestamp_to_event returning outliers that it has no idea whether are near a gap or not (#14215) 2022-10-18 19:46:25 -05:00
streams Do not allow a None-limit on PaginationConfig. (#14146) 2022-10-14 12:30:05 +00:00
util Making parse_server_name more consistent (#14007) 2022-10-11 12:42:11 +00:00
__init__.py Parse SYNAPSE_ASYNC_IO_REACTOR env variable & log the reactor on startup (#14092) 2022-10-07 15:19:59 +01:00
event_auth.py Prepatory work for adding power level event to batched events (#14214) 2022-10-18 09:58:47 -07:00
notifier.py Batch up notifications after event persistence (#14033) 2022-10-05 10:12:48 -07:00
py.typed Mark Module API error imports as re-exported and mark Synapse as containing type annotations (#11054) 2021-10-13 08:42:41 +01:00
server.py Fix error in is_mine_id when encountering a malformed ID (#13746) 2022-09-08 15:54:36 +01:00
types.py Accept & store thread IDs for receipts (implement MSC3771). (#13782) 2022-09-23 14:33:28 +00:00
visibility.py Add debug logs to figure out why an event was filtered (#14095) 2022-10-17 16:02:39 -05:00