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

Potential fix stuck local echo events at the bottom of the screen #4928

Merged
merged 2 commits into from
Jan 13, 2022

Conversation

ariskotsomitopoulos
Copy link
Contributor

@ariskotsomitopoulos ariskotsomitopoulos commented Jan 12, 2022

This PR will try to fix issues like #516 that report stuck local echo events. The fix not only prevent this from happening again but after a user update its device, stuck local echos will be cleared

Why this is happening?

The issue can happen when a message is SENT but not received back from the /sync.
Until now we use unsignedData.transactionId to determine whether or not the local
event should be deleted on every /sync. However, this is partially correct, lets have a look
at the following scenario:

There is no Internet connection10 Messages are sentcant be sent so the 10 messages are in the queueinternet comes back for 1 second3 messages are sent to the homeserverInternet drops againNo /sync response is triggered | home server can even replied with /sync but never arrived while we are offline

So the state until now is that we have 7 pending events to send and 3 sent but not received them back from /sync
Subsequently, those 3 local messages will not be deleted from the device while there is no transactionId from the /sync

lets continue:
Now lets assume that in the same room another user sent 15 eventsWe are finally back online!we will receive the 10 latest events for the room and of course sent the pending 7 messagesNow /sync response will NOT contain the 3 local messages so our events will stuck in the device.

Someone can say, yes but it will come with the rooms/{roomId}/messages while paginating, so the problem will be solved. No that is not the case for two reasons:

  1. rooms/{roomId}/messages response do not contain the unsignedData.transactionId so we cannot know which event to delete (in the doc says it should but, it does not)
  2. even if transactionId was there, currently we are not deleting it from the pagination

While we cannot know when a specific event arrived from the pagination (no transactionId included), after each room /sync a solution is to clear all SENT events, and we are sure that we will receive it from /sync or pagination

Before the fix
https://user-images.githubusercontent.com/60798129/149152854-76a0aff6-5925-4e1c-bbf2-b7c96282869c.mp4

After the fix
https://user-images.githubusercontent.com/60798129/149153207-94e54325-8c2b-49cd-b7d9-39534620ae6c.mp4

@ariskotsomitopoulos
Copy link
Contributor Author

ariskotsomitopoulos commented Jan 12, 2022

@bmarty @ganfra @ouchadam we can further discuss about it maybe there are better alternatives

roomEntity.sendingTimelineEvents.filter { timelineEvent ->
timelineEvent.root?.sendState == SendState.SENT
}.forEach {
roomEntity.sendingTimelineEvents.remove(it)
Copy link
Contributor

Choose a reason for hiding this comment

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

great explanation of the scenario! 💯

are the sendingTimelineEvents the local echos?

I'm wondering if we could clean up when we set the sendState to SENT (or is that what this logic is acting on?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes and I guess yes we can, but if we do that we will remove the echos at once. So until the user is back online echos will not be visible.

@github-actions
Copy link

Unit Test Results

  66 files  ±0    66 suites  ±0   51s ⏱️ -8s
135 tests ±0  135 ✔️ ±0  0 💤 ±0  0 ±0 
418 runs  ±0  418 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit 6f5f773. ± Comparison against base commit c194568.

@bmarty
Copy link
Member

bmarty commented Jan 12, 2022

According to your great explanation and videos, it seems to work!

I am even wondering if we should remove the existing local echo cleanup

@ganfra can you share your thoughts?

@ganfra
Copy link
Member

ganfra commented Jan 12, 2022

Thanks for the explanation!
Indeed it will fix the issue, but it can leads to cases where we don't see at our sent events for some time (sync can be slow)
So not sure thats the best move... maybe we should try again to set the event in the last forward chunk instead of being in a dedicated event list, so it won't be stuck at the bottom at least...

@ariskotsomitopoulos
Copy link
Contributor Author

@bmarty I think it's ok to delete it, there will be no difference without it. However, we have an optimisation logic there that passes the decrypted event at once without the need to decrypt it again. So we should keep the logic there at least

@ganfra To my understanding, yes in a very slow /sync some messages will be delayed but at the end will be with the correct order and delivered. While a lot of people complain about it, and it is really frustrating for the user (can't be undone if that happens). If the only problem is the slow sync and there are no more caveats maybe we can merge it and then try a better solution.

@bmarty
Copy link
Member

bmarty commented Jan 13, 2022

As discussed IRL, lets merge the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants