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

Fix a bug which could lead to incorrect state #13278

Merged
merged 11 commits into from
Jul 15, 2022
5 changes: 5 additions & 0 deletions synapse/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,11 @@ def _make_state_cache_entry(
delta_ids: Optional[StateMap[str]] = None

for old_group, old_state in state_groups_ids.items():
if old_state.keys() - new_state.keys():
# Currently we don't support deltas that remove keys from the state
# map.
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
continue

n_delta_ids = {k: v for k, v in new_state.items() if old_state.get(k) != v}
if not delta_ids or len(n_delta_ids) < len(delta_ids):
prev_group = old_group
Expand Down
4 changes: 3 additions & 1 deletion synapse/storage/controllers/persist_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,8 @@ async def _get_new_state_after_events(
state_res_store=StateResolutionStore(self.main_store),
)

full_state = await res.get_state(self._state_controller)
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved

state_resolutions_during_persistence.inc()

# If the returned state matches the state group of one of the new
Expand All @@ -948,7 +950,7 @@ async def _get_new_state_after_events(
events_context,
)

return res.state, None, new_latest_event_ids
return full_state, None, new_latest_event_ids
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops. Sorry.


async def _prune_extremities(
self,
Expand Down