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

Deal with out-of-sync room state, e.g. due to the last device logging out or leaving the room #18

Closed
kegsay opened this issue Jan 5, 2023 · 1 comment · Fixed by #71
Labels
bug Something isn't working
Milestone

Comments

@kegsay
Copy link
Member

kegsay commented Jan 5, 2023

If you have 1 user with 1 device in a room, who then leaves the room, the room data in the DB will eventually go stale. However, if a new user then joins the same room, we will not reset our knowledge of room state (specifically, we discard the state in the sync response), and the room state can then diverge from the truth.

This isn't terribly dissimilar to when servers leave a room then rejoin the same room - they need to clear their DB when they leave.

@kegsay kegsay added the bug Something isn't working label Jan 5, 2023
@kegsay kegsay changed the title Delete rooms when the last device in that room logs out Delete rooms when the last device in that room logs out or leaves Jan 5, 2023
@kegsay kegsay added this to the v1 milestone Mar 27, 2023
@DMRobertson
Copy link
Contributor

(Hashed out in #51 (comment) .)

It's true enough that room state in the proxy's DB can become out of date. (Indeed, we suspect that something like this has already happened---there are reports of old room names showing up.) However, deleting everything and starting from scratch is a little nuclear. Instead we can do the following.

  • Whenever a poller sees a state block in an incremental sync v2 response, select the NIDs from the proxy database, for all event IDs in the state block.
  • If they all have NIDs then the proxy's view of state is in sync with the HS, and all is well.
  • Otherwise, prepend all events missing a NID to the timeline so that clients see the new state.
    • The timeline order will be wrong, but at least both the proxy and the client will now see up to date state---we've self-healed.
    • Is the order in which we do this important? E.g. if A invited B, should we show A's membership before B's?

Slogan: this makes the proxy "support gappy state" (but not gappy messages).

Other notes:

  • This needs to all happen within a single database transaction.
    • do we also want to SELECT FOR UPDATE or similar?
  • If we prepend events to timeline then we should write error log lines and make lots of noise in Sentry.

@DMRobertson DMRobertson changed the title Delete rooms when the last device in that room logs out or leaves Deal with out-of sync room state, e.g. due to the last device logging out or leaving the room Apr 12, 2023
@DMRobertson DMRobertson changed the title Deal with out-of sync room state, e.g. due to the last device logging out or leaving the room Deal with out-of-sync room state, e.g. due to the last device logging out or leaving the room Apr 12, 2023
DMRobertson pushed a commit that referenced this issue Apr 14, 2023
Reduces the likelihood of hitting #18.
DMRobertson pushed a commit that referenced this issue Apr 14, 2023
Reduces the likelihood of hitting #18.
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