Skip to content

Chunked sending of to_device messages may not retry correctly #2290

@krille-chan

Description

@krille-chan

Checklist

  • I could not find a solution in the documentation, the existing issues or discussions.
  • I already asked for help in the chat

In which Project did the bug appear?

Other

If you selected "Other" as Project, please enter in which project the bug occurred.

FluffyChat

On which platform did the bug appear?

Android, iOS, Chrome, Firefox, Edge, Safari

SDK Version

latest

Describe the problem caused by this bug

Original report from @kegsay from krille-chan/fluffychat#1142 (comment)

Seen this again on 1.22.0

I believe the fault lies in https://github.com/famedly/matrix-dart-sdk/blob/v0.32.4/lib/src/client.dart#L3270-L3306 somewhere because the failure mode I'm seeing is that some devices can decrypt the message but others cannot, and which devices can/cannot does not seem to be based on the HS domain or anything.

I suspect that if some of the chunks fails, we do not retry them, causing UTDs.

A few suspect things:

https://github.com/famedly/matrix-dart-sdk/blob/v0.32.4/lib/src/client.dart#L3181 - this is only added to the database after a failure. If the app is SIGKILLed before this, the to-device msgs will be lost. This could be the cause as in at least one of these bug reports the sender closed the app because it was getting slow, so it may have been mid-sending of keys.
Upon retry in https://github.com/famedly/matrix-dart-sdk/blob/v0.32.4/lib/src/client.dart#L3157 it looks like we always delete from the database if the retry fails, regardless of the outcome.

Steps To Reproduce

No response

Screenshots or Logs

No response

Security related

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions