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 case of lost messages: Do not delete events from the last forward chunk #5878

Closed
wants to merge 6 commits into from

Conversation

SpiritCroc
Copy link
Contributor

@SpiritCroc SpiritCroc commented Apr 30, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Motivation and context

We get end up with missing messages by the combination of

  • deleting the last forward chunk when receiving a new one
  • not adding events to a chunk that are already found in another chunk

Accordingly, when using chunk tokens to load more messages, those
messages that were not added to a chunk due to a /sync chunk will get
lost.

Content

Before deleting the latest chunk, move the events to the previous chunk, if applicable.
Also make sure we do not link in the wrong direction because we found these events, to prevent timeline loops.

Tests

  • Receive e.g. 30 new messages while offline
  • Use /sync in the room overview, this will fetch the latest 10 events
  • Open a chat in the past before the latest unread messages
  • Scroll down a little, in order to fill the message gap and load all
    unread messages
  • Close the chat
  • Receive another e.g. 60 messages while offline
  • Re-open the chat at some time in the past, before the latest 70
    messages
    => messages from the old /sync chunk will be missing

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

Signed-off-by: Tobias Büttner [email protected]

We get end up with missing messages by the combination of
- deleting the last forward chunk when receiving a new one
- not adding events to a chunk that are already found in another chunk

Accordingly, when using chunk tokens to load more messages, those
messages that were not added to a chunk due to a /sync chunk will get
lost. More thorough steps to reproduce:

- Receive e.g. 30 new messages while offline
- Use /sync in the room overview, this will fetch the latest 10 events
- Open a chat in the past before the latest unread messages
- Scroll down a little, in order to fill the message gap and load all
  unread messages
- Close the chat
- Receive another e.g. 60 messages while offline
- Re-open the chat at some time in the past, before the latest 70
  messages
  => messages from the old /sync chunk will be missing

Change-Id: Ia3f2d2715a3edfd0b3fe5c3d48a02ade4ea49c4d
If we link chunks in pagination direction, and discard all events after
that, we assume that we reached a point in the chunk that is already
covered by a different chunk.
If we however haven't seen any new events in that chunk yet, chances are
this is the wrong direction we are linking. So in this case, better just
skip related events and continue processing later events - making sure
we don't lose new events and don't link in the wrong direction.

Note we could also enforce links into the opposite direction in this case.
Since in the cases I observed so far, such link already existed, so I
think this is probably not necessary.

Change-Id: Ia4d2fd87188b9757ed68416e883c3fb489cdfa6e
@SpiritCroc SpiritCroc changed the title Do not delete events from the last forward chunk Fix case of lost messages: Do not delete events from the last forward chunk Apr 30, 2022
@ouchadam ouchadam requested a review from ganfra May 9, 2022 08:25
@ouchadam ouchadam added the Z-Community-PR Issue is solved by a community member's PR label May 9, 2022
@ganfra
Copy link
Member

ganfra commented May 10, 2022

I'm wondering if we should instead always add TimelineEvent to chunk and let the timeline remove duplicates if any

@SpiritCroc
Copy link
Contributor Author

I'm wondering if we should instead always add TimelineEvent to chunk and let the timeline remove duplicates if any

Sounds to me like the logic for that approach would be easier to understand and less prone to bugs at least. 🤔

If we already have some events in a previously linked chunk, that
doesn't mean we have all of them. So we still want to continue
processing later events in that case.
@ganfra
Copy link
Member

ganfra commented Jun 17, 2022

See #6318

@ganfra ganfra closed this Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants