element-hq / element-x-android

Android Matrix messenger application using the Matrix Rust Sdk and Jetpack Compose
GNU Affero General Public License v3.0
1.08k stars 155 forks source link

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

Closed jmartinesp closed 1 month ago

jmartinesp commented 2 months ago

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 https://github.com/element-hq/element-x-android/pull/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

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

Checklist

github-actions[bot] commented 2 months ago

:iphone: 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

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

bmarty commented 2 months ago

We should be extra careful to also include this same behaviour to account deactivation after https://github.com/element-hq/element-x-android/pull/3479 if this PR is merged.

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

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud