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

Add another yield point to state res v2 #7746

Merged
merged 2 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7746.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix large state resolutions from stalling Synapse for seconds at a time.
12 changes: 10 additions & 2 deletions synapse/state/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def resolve_events_with_store(

# Now sequentially auth each one
resolved_state = yield _iterative_auth_checks(
clock,
room_id,
room_version,
sorted_power_events,
Expand Down Expand Up @@ -154,6 +155,7 @@ def resolve_events_with_store(
logger.debug("resolving remaining events")

resolved_state = yield _iterative_auth_checks(
clock,
room_id,
room_version,
leftover_events,
Expand Down Expand Up @@ -378,12 +380,13 @@ def _get_power_order(event_id):

@defer.inlineCallbacks
def _iterative_auth_checks(
room_id, room_version, event_ids, base_state, event_map, state_res_store
clock, room_id, room_version, event_ids, base_state, event_map, state_res_store
):
"""Sequentially apply auth checks to each event in given list, updating the
state as it goes along.

Args:
clock (Clock)
room_id (str)
room_version (str)
event_ids (list[str]): Ordered list of events to apply auth checks to
Expand All @@ -397,7 +400,7 @@ def _iterative_auth_checks(
resolved_state = base_state.copy()
room_version_obj = KNOWN_ROOM_VERSIONS[room_version]

for event_id in event_ids:
for idx, event_id in enumerate(event_ids, start=1):
event = event_map[event_id]

auth_events = {}
Expand Down Expand Up @@ -435,6 +438,11 @@ def _iterative_auth_checks(
except AuthError:
pass

# We yield occasionally when we're working with large data sets to
# ensure that we don't block the reactor loop for too long.
if idx % _YIELD_AFTER_ITERATIONS == 0:
yield clock.sleep(0)

return resolved_state


Expand Down