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

incoming encrypted to-device messages can be lost when the application is restarted #762

Closed
BillCarsonFr opened this issue Oct 14, 2022 · 7 comments
Labels
A-E2EE O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Critical Prevents work, causes data loss and/or has no workaround T-Defect Team: Crypto Z-Awaiting-Element-R Issues in code which will be replaced by the port of Element's crypto layer to Rust Z-Chronic

Comments

@BillCarsonFr
Copy link
Member

BillCarsonFr commented Oct 14, 2022

If you restart /upgrade (web) or the app is killed in background while processing to_devices coming down the sync, the non decrypted to_devices will be dropped and lost producing UISIs.

This is problem with atomicity of /sync. The sync token is persisted before all to_devices have been processed, so the next time the app launches it will use the saved token, thus ack'ing the previous to_device chunk that was received. In such case the app should start syncing with the previous token to force a redelivery of the initial to_device chunk (or make sure that it permanently persists the to-device messages before storing the /sync token). Olm session internal state should also be reverted if the sync does not complete.

@richvdh richvdh changed the title To device sync decryption Reliability encrypted to-devices messages can be lost when the application is restarted Nov 14, 2022
@richvdh
Copy link
Member

richvdh commented Nov 14, 2022

@BillCarsonFr:

Olm session internal state should also be reverted if the sync does not complete.

Why is this required?

@richvdh richvdh changed the title encrypted to-devices messages can be lost when the application is restarted encrypted to-device messages can be lost when the application is restarted Jan 12, 2023
@richvdh richvdh changed the title encrypted to-device messages can be lost when the application is restarted incoming encrypted to-device messages can be lost when the application is restarted Jan 12, 2023
@richvdh richvdh added the Z-Awaiting-Element-R Issues in code which will be replaced by the port of Element's crypto layer to Rust label Mar 15, 2023
@pmaier1
Copy link
Contributor

pmaier1 commented Apr 4, 2023

Will be fixed with the introduction of ER.

@kittykat kittykat added O-Uncommon Most users are unlikely to come across this or unexpected workflow T-Defect S-Critical Prevents work, causes data loss and/or has no workaround labels Apr 6, 2023
@BillCarsonFr
Copy link
Member Author

Will be fixed with the introduction of ER.

Looks like not. The sync token is save way to early (on purpose?), before the to_devices have been processed by the rust sdk.
So in case of restart, the next token will be used and thus the to_devices not processed are lost.

https://github.com/matrix-org/matrix-js-sdk/blob/748d03ba1129dd0ab6ce6e44f6202b81e604a4b3/src/sync.ts#L895

            // set the sync token NOW *before* processing the events. We do this so
            // if something barfs on an event we can skip it rather than constantly
            // polling with the same token.
            this.client.store.setSyncToken(data.next_batch);

@richvdh
Copy link
Member

richvdh commented Mar 1, 2024

Similar issue on android
Similar on iOS?

Do we actually have any evidence that EAR and EIR are similarly affected? The Rust SDK makes this much harder to mess up than before, so I don't see it as a given that the other platforms have the same problem

@richvdh
Copy link
Member

richvdh commented Mar 4, 2024

Given that element-hq/element-web#23113 is now closed, and we have no reports of it happening on EAR and EIR, can we close this?

@BillCarsonFr
Copy link
Member Author

Given that element-hq/element-web#23113 is now closed, and we have no reports of it happening on EAR and EIR, can we close this?

Confirm that android only saves the token after all the to_devices have been processed.

For iOS I am not sure for the background sync (NSE). Looks like the crypto sync is handled after the call to syncResponseStoreManager.updateStore

So possible that the background sync of IOS is affected?

@BillCarsonFr
Copy link
Member Author

Ok so it's also fine for IOS.
The NSE background sync will save the sync response anyhow, and the next time the app starts it will then start from the token persisted by the app side, and will process the cached syncs (to avoid another server call). So IOS is actually in some condition replaying the to_device (can be seen in various RS An Olm message got replayed) and not dropping them.

So closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-E2EE O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Critical Prevents work, causes data loss and/or has no workaround T-Defect Team: Crypto Z-Awaiting-Element-R Issues in code which will be replaced by the port of Element's crypto layer to Rust Z-Chronic
Projects
None yet
Development

No branches or pull requests

4 participants