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

Avoid deadlocks when ensuring Olm sessions for devices #1627

Merged
merged 5 commits into from
Mar 2, 2021

Conversation

jryans
Copy link
Collaborator

@jryans jryans commented Mar 2, 2021

This reworks tracking the Olm sessions a particular task is updating to avoid deadlocks. By ensuring we synchronously mark all sessions a task cares about as in progress from the start, we know that no other tasks will own updating a session in common, which avoids deadlocks across multiple tasks that might be working on a shared set of devices.

The potential for deadlocks first appeared with #857 (2 years ago), but I believe it would be unlikely for most users to trigger this deadlock during normal usage. The app would need to be sluggish enough to permit stacking up several messages in different rooms with devices in common, which is most likely only possible on larger accounts. In any case, with this change, this process should now avoid deadlocks in all cases.

Fixes element-hq/element-web#16194

This avoids logging immediately on various code paths (including tests) where no
timeout value is supplied.
This reworks tracking the Olm sessions a particular task is updating to avoid
deadlocks. By ensuring we synchronously mark all sessions a task cares about as
in progress from the start, we know that no other tasks will own updating a
session in common, which avoids deadlocks across multiple tasks that might be
working on a shared set of devices.

Fixes element-hq/element-web#16194
This removes the unused `reject` path for in progress Olm sessions to simplify
understanding the code.
This removes extra steps that duplicated deletion of an in progress Olm session.
Resolving the promise handles removing the session from the in progress set, so
there's no need to do it again. There's also no need to delete from
`resolveSession`, as it's okay to resolve a promise multiple times.
@jryans jryans requested a review from a team March 2, 2021 13:12
@dbkr dbkr requested review from dbkr and removed request for a team March 2, 2021 14:28
Copy link
Member

@dbkr dbkr left a comment

Choose a reason for hiding this comment

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

Phew, well done for tracking that one down.

@jryans jryans merged commit 31dacc4 into develop Mar 2, 2021
@t3chguy t3chguy deleted the jryans/olm-session-deadlock branch May 10, 2022 14:37
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.

Sending E2EE messages during app startup can wedge all E2EE sending.
2 participants