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

Database corruption when servers backfill over federation #192

Closed
kegsay opened this issue Jul 6, 2023 · 2 comments · Fixed by #198
Closed

Database corruption when servers backfill over federation #192

kegsay opened this issue Jul 6, 2023 · 2 comments · Fixed by #198
Labels
bug Something isn't working

Comments

@kegsay
Copy link
Member

kegsay commented Jul 6, 2023

Consider:

  • Bob on his server invites Alice to a room.
  • Alice joins the room first over federation. Proxy does the right thing and sets her membership to join. There is no timeline though due to not having backfilled.
  • Alice's client backfills in the room which pulls in the invite event, but the SS proxy doesn't see it as it's backfill, not /sync.
  • Charlie joins the same room via SS, which makes the SS proxy see 50 timeline events, which includes the invite. As the proxy has never seen this invite event before, it assumes it is newer than the join event and inserts it, corrupting state.

To fix this:

  • SELECT nids for all events prior to insertion.
  • Find the lowest-index which has a NID and drop all events earlier than this as they are backfilled.
  • Discard the state block when this happens, as it cannot be trusted to do the right thing now that we are dropping parts of the timeline.
@DMRobertson
Copy link
Contributor

  • Find the lowest-index which has a NID and drop all events earlier than this as they are backfilled.

earlier in what sense---origin server TS?

@DMRobertson
Copy link
Contributor

Answer: earlier meaning lower index in the timeline given to use in the sync v2 poll payload.

@DMRobertson DMRobertson linked a pull request Jul 12, 2023 that will close this issue
kegsay added a commit that referenced this issue Jul 12, 2023
@kegsay kegsay closed this as completed in e947612 Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants