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

Make sure the logout action doesn't cause a crash #3480

Merged
merged 3 commits into from
Sep 18, 2024

Conversation

jmartinesp
Copy link
Member

Content

Making sure to unregister the delegate should fix the first part of the issue.

For the other one, adding RustSyncService.isServiceReady to check if we should start/stop the service, which is enabled by default and set to false on destroy should help.

We should be extra careful to also include this same behaviour to account deactivation after #3479 if this PR is merged.

Motivation and context

Some reasons why this could happen:

  1. The ClientDelegate could receive a didReceiveAuthError callback call on a logout, which could trigger another logout when every Rust object had already been destroyed.
  2. Even though we stop the sync before logging out, LoggedInFlowNode will try to start it again automatically when it detects we still have internet connection.

Tests

  • Log in, log out, several times.

If it doesn't create a crash anymore, it's fixed. Also, failures while logging out should restore the client delegate and allow the user to keep refreshing their token and receive auth errors.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

  • Changes have been tested on an Android device or Android emulator with API 23
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • Pull request includes a sign off
  • You've made a self review of your PR

Some reasons why this could happen:
1. The `ClientDelegate` could receive a `didReceiveAuthError` callback call on a logout, which could trigger another logout when every Rust object had already been destroyed.
2. Even though we stop the sync before logging out, `LoggedInFlowNode` will try to start it again automatically when it detects we still have internet connection.

Making sure to unregister the delegate should fix the first part of the issue.

For the other one, adding `RustSyncService.isServiceReady` to check if we should start/stop the service, which is enabled by default and set to false on destroy should help.
@jmartinesp jmartinesp added the PR-Bugfix For bug fix label Sep 17, 2024
@jmartinesp jmartinesp requested a review from a team as a code owner September 17, 2024 15:32
@jmartinesp jmartinesp requested review from bmarty and removed request for a team September 17, 2024 15:32
@@ -50,7 +50,6 @@ class RustClientSessionDelegate(
*/
fun bindClient(client: RustMatrixClient) {
this.client = client
client.setDelegate(this)
Copy link
Member Author

Choose a reason for hiding this comment

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

This was never really needed, as RustMatrixClient automatically sets its inner Client delegate.

Copy link
Contributor

github-actions bot commented Sep 17, 2024

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/jShSH2

Copy link

codecov bot commented Sep 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.66%. Comparing base (f0bb1fa) to head (1473afc).
Report is 6 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3480   +/-   ##
========================================
  Coverage    82.66%   82.66%           
========================================
  Files         1731     1731           
  Lines        40829    40829           
  Branches      4964     4964           
========================================
  Hits         33750    33750           
  Misses        5320     5320           
  Partials      1759     1759           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bmarty
Copy link
Member

bmarty commented Sep 17, 2024

We should be extra careful to also include this same behaviour to account deactivation after #3479 if this PR is merged.

Done in 1473afc if you want to have a quick look @jmartinesp

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

LGTM, thanks
Related to #3478

Copy link

@jmartinesp jmartinesp added the Run-Maestro Starts a Maestro Cloud session to run integration tests label Sep 18, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label Sep 18, 2024
@jmartinesp jmartinesp enabled auto-merge (squash) September 18, 2024 06:31
override suspend fun startSync() = runCatching {
if (!isServiceReady.get()) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need those checks, the failure will be catched by runCatching anyway

Copy link
Member Author

Choose a reason for hiding this comment

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

This way we can have more detailed logging in case we run into a similar issue in the future, but you're right, it's not really needed.

Copy link
Member

Choose a reason for hiding this comment

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

With the runcatching we are already logging the exception if I'm correct

Timber.i("Start sync")
innerSyncService.start()
}.onFailure {
Timber.d("Start sync failed: $it")
}

override suspend fun stopSync() = runCatching {
if (!isServiceReady.get()) {
Copy link
Member

Choose a reason for hiding this comment

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

Same

@jmartinesp jmartinesp merged commit c08b8c0 into develop Sep 18, 2024
30 checks passed
@jmartinesp jmartinesp deleted the fix/jme/prevent-crash-on-logout branch September 18, 2024 11:54
@bmarty bmarty mentioned this pull request Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Bugfix For bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants