-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix 500 error on /messages
when we accumulate more than 5 backward extremities
#11027
Changes from 7 commits
4cb7d09
94b9efb
7364b81
0ceaf25
694ca81
4e75ea3
85748bd
6a119a4
391bc73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix 500 error on `/messages` when the server accumulates more than 5 backwards extremities at a given depth for a room. |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -240,28 +240,30 @@ async def _maybe_backfill_inner( | |||||||
) | ||||||||
return False | ||||||||
|
||||||||
logger.debug( | ||||||||
"room_id: %s, backfill: current_depth: %s, max_depth: %s, extrems: %s", | ||||||||
room_id, | ||||||||
current_depth, | ||||||||
max_depth, | ||||||||
sorted_extremeties_tuple, | ||||||||
) | ||||||||
|
||||||||
# We ignore extremities that have a greater depth than our current depth | ||||||||
# as: | ||||||||
# 1. we don't really care about getting events that have happened | ||||||||
# before our current position; and | ||||||||
# after our current position; and | ||||||||
# 2. we have likely previously tried and failed to backfill from that | ||||||||
# extremity, so to avoid getting "stuck" requesting the same | ||||||||
# backfill repeatedly we drop those extremities. | ||||||||
filtered_sorted_extremeties_tuple = [ | ||||||||
t for t in sorted_extremeties_tuple if int(t[1]) <= current_depth | ||||||||
] | ||||||||
|
||||||||
logger.debug( | ||||||||
"room_id: %s, backfill: current_depth: %s, limit: %s, max_depth: %s, extrems: %s filtered_sorted_extremeties_tuple: %s", | ||||||||
room_id, | ||||||||
current_depth, | ||||||||
limit, | ||||||||
max_depth, | ||||||||
sorted_extremeties_tuple, | ||||||||
filtered_sorted_extremeties_tuple, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this below because it's useful to see what |
||||||||
) | ||||||||
|
||||||||
# However, we need to check that the filtered extremities are non-empty. | ||||||||
# If they are empty then either we can a) bail or b) still attempt to | ||||||||
# backill. We opt to try backfilling anyway just in case we do get | ||||||||
# backfill. We opt to try backfilling anyway just in case we do get | ||||||||
# relevant events. | ||||||||
if filtered_sorted_extremeties_tuple: | ||||||||
sorted_extremeties_tuple = filtered_sorted_extremeties_tuple | ||||||||
|
@@ -318,7 +320,7 @@ async def try_backfill(domains: List[str]) -> bool: | |||||||
for dom in domains: | ||||||||
try: | ||||||||
await self._federation_event_handler.backfill( | ||||||||
dom, room_id, limit=100, extremities=extremities | ||||||||
dom, room_id, limit=100, extremities=extremities.keys() | ||||||||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
) | ||||||||
# If this succeeded then we probably already have the | ||||||||
# appropriate stuff. | ||||||||
|
@@ -391,7 +393,7 @@ async def try_backfill(domains: List[str]) -> bool: | |||||||
for key, state_dict in states.items() | ||||||||
} | ||||||||
|
||||||||
for e_id, _ in sorted_extremeties_tuple: | ||||||||
for e_id in event_ids: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The big bug fix is here! I am iterating over Previously if we had say 8 backward extremities ( synapse/synapse/handlers/federation.py Lines 269 to 271 in e79ee48
Then we fetch the state for those 5 But then later, we looped over |
||||||||
likely_extremeties_domains = get_domains_from_state(states[e_id]) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A general question on the MSC2716 front. I ran into this error because each historical batch creates a backward extremity that will never be able to resolve because it points to a fake Is it okay to have this build-up? My thinking is this would be problematic as we will have thousands of batches per room to backfill a big room for Gitter and will have to deal with thousands of backward extremities here. Also because we use I feel like I may be missing something though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh bleurgh, that's true. Ideally we'd know that those are fake prev events and not store them? Or something like that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tracking this separately via #11091 |
||||||||
|
||||||||
success = await try_backfill( | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've read this over many times. I am pretty sure this is a typo or the logic below is wrong,
t for t in sorted_extremeties_tuple if int(t[1]) <= current_depth
Let's just assume the code is correct and the source of truth. The code also matches the general summary above "We ignore extremities that have a greater depth than our current depth"
Depth is incremented for new messages.
Say our
current_depth
is1
and the extremities are at depth10
, the extremities occurred after our current place. And the logic below will ignore any extremities greater than1
.Therefore, "we don't really care about getting events that have happened after our current position"