Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RewritesState bug #1557

Merged
merged 10 commits into from
Oct 22, 2020
Merged

Fix RewritesState bug #1557

merged 10 commits into from
Oct 22, 2020

Conversation

neilalexander
Copy link
Contributor

@neilalexander neilalexander commented Oct 21, 2020

Apparently we were overwriting RewritesState when generating new output events and didn't bother to check u.rewritesState the second time. This meant that we were probably sending rewrite output events far more often than we intended to, confusing downstream component state.

This also updates the sync API to only discard state, rather than the entire room history, since that can cause problems with events going missing from the timeline, and also fixes a bug that can result in a panic if the federation sender gets the same joined hosts more than once.

Copy link
Member

@kegsay kegsay left a comment

Choose a reason for hiding this comment

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

Reads well!

@@ -125,7 +124,8 @@ func (u *latestEventsUpdater) doUpdateLatestEvents() error {
// then start with an empty set - none of the forward extremities
// that we knew about before matter anymore.
oldLatest := []types.StateAtEventAndReference{}
if !u.stateAtEvent.Overwrite {
if !u.rewritesState {
u.oldStateNID = u.updater.CurrentStateSnapshotNID()
Copy link
Member

Choose a reason for hiding this comment

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

Whilst this makes sense, why did you change it so it's only set if we don't rewrite state? I think updater.CurrentStateSnapshotNID() just returns an int - the New... function did the DB query so it's not even an optimisation. Maybe to act as a guard against accidentally fiddling with it and calculating deltas against things we shouldn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is that, if we are rewriting state, we want the state snapshot NID to be zero because that means that the deltas produced later on will be against an empty snapshot (effectively a complete rewrite, where AddsStateEventIDs will contain the entire new state).

If we aren't rewriting state, we want to know what the current state is so that we produce a real delta.

@neilalexander neilalexander merged commit 3afc623 into master Oct 22, 2020
@neilalexander neilalexander deleted the neilalexander/rewrite branch October 22, 2020 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants