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

Restore manual Client cleanup on session logout #4333

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

jmartinesp
Copy link
Member

Content

  • Restore Client instances and related dependencies cleanup when the user logs out.
  • Try to minimise the number of strong references to Client/MatrixClient.
  • Also try to wrap more calls to the SDK with runCatching to prevent issues if some component is called when its Rust reference has been destroyed.

Motivation and context

This is done as a workaround for #4326.

Tests

Log out, check the Client is not running in the background anymore.

Tested devices

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

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • 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
  • You've made a self review of your PR

@jmartinesp jmartinesp added the PR-Bugfix For bug fix label Feb 27, 2025
@jmartinesp jmartinesp requested a review from a team as a code owner February 27, 2025 15:04
@jmartinesp jmartinesp requested review from bmarty and removed request for a team February 27, 2025 15:04
Copy link
Contributor

github-actions bot commented Feb 27, 2025

📱 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/jUvzut

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 61.11111% with 7 lines in your changes missing coverage. Please review.

Project coverage is 80.17%. Comparing base (fe99ec0) to head (91da7fe).
Report is 32 commits behind head on develop.

Files with missing lines Patch % Lines
...atrix/impl/auth/RustMatrixAuthenticationService.kt 0.00% 3 Missing ⚠️
...libraries/matrix/impl/RustClientSessionDelegate.kt 60.00% 2 Missing ⚠️
...es/matrix/impl/encryption/RustEncryptionService.kt 33.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4333      +/-   ##
===========================================
- Coverage    80.17%   80.17%   -0.01%     
===========================================
  Files         2058     2058              
  Lines        54792    54805      +13     
  Branches      6707     6708       +1     
===========================================
+ Hits         43928    43938      +10     
- Misses        8565     8568       +3     
  Partials      2299     2299              

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

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!

@@ -101,7 +109,7 @@ class RustClientSessionDelegate(
} else {
clientLog.d("No session data found.")
}
client?.logout(userInitiated = false, ignoreSdkError = true)
client.get()?.logout(userInitiated = false, ignoreSdkError = true)
Copy link
Member

Choose a reason for hiding this comment

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

This is not new, but I am wondering why we are not using currentClient here (instead of client.get()?).

Copy link
Member Author

Choose a reason for hiding this comment

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

No reason, it's better to use currentClient indeed!

This is done to fix an issue where the Nodes that contain these dependencies are leaked and the `Client` and other SDK-related components can keep working in background for a while, until the caches holding the Nodes are flushed or the app is restarted.
@jmartinesp jmartinesp force-pushed the fix/restore-client-manual-cleanup-on-logout branch from 280ba98 to 91da7fe Compare February 27, 2025 15:39
@jmartinesp jmartinesp enabled auto-merge (squash) February 27, 2025 15:39
@jmartinesp jmartinesp merged commit 7aa6a43 into develop Feb 27, 2025
26 checks passed
@jmartinesp jmartinesp deleted the fix/restore-client-manual-cleanup-on-logout branch February 27, 2025 16:04
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.

2 participants