This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
Fully sync the devices with the homeserver #2971
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2626
When we end session, instead of imperatively delete devices, we now sync the device list with Synapse.
This means that if two sessions have the same device, it will not wrongly delete the device.
It also means it's less likely for the device list to get out of sync.
This also makes all the devices creation synchronous, to make sure they exist on Synapse before we start using the new sessions.
This also uses per-user PG advisory locks around device syncing, to make sure we don't have race conditions when syncing those
Old rant about locking kept for posterity
One thing which I'm very not sure about is that there is potential races between the device creations and the device sync.
If there is an ongoing sync job, the sync job might build a list of devices from the database that doesn't have a new device. That device may already have been created from somewhere else on the homeserver, but haven't been committed yet to the database.
If this is the case, the device syncing job will delete from the homeserver the newly added device.
This is very unlikely to happen though, as we would need the user to login and logout at the same time. I'm not sure what the best way would be to make sure it never happens. A few possibilities I have in mind: