Skip to content

Ensure that we have only one single instance of SeenInviteStore per session #4577

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

Merged
merged 2 commits into from
Apr 11, 2025

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Apr 11, 2025

Content

Ensure that we have only one single instance of SeenInviteStore per session by using a SeenInviteStoreFactory.

Motivation and context

Fix crash:
java.lang.IllegalStateException: There are multiple DataStores active for the same file: /data/user/0/io.element.android.x/files/datastore/session_0ebb139587b6d940_seen-invites.preferences_pb. You should either maintain your DataStore as a singleton or confirm that there is no two DataStore's active on the same file (by confirming that the scope is cancelled).

Fixes #4559

Screenshots / GIFs

Tests

  • Run the app
  • From an external app (for instance a photo app), share something to Element X
  • If the app does not crash, the bug is fixed.

Tested devices

  • Physical
  • Emulator
  • OS version(s):

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

…ession. Fixes #4558

Fix crash:
java.lang.IllegalStateException: There are multiple DataStores active for the same file: /data/user/0/io.element.android.x/files/datastore/session_0ebb139587b6d940_seen-invites.preferences_pb. You should either maintain your DataStore as a singleton or confirm that there is no two DataStore's active on the same file (by confirming that the scope is cancelled).
@bmarty bmarty added the PR-Bugfix For bug fix label Apr 11, 2025
@bmarty bmarty marked this pull request as ready for review April 11, 2025 10:12
@bmarty bmarty requested a review from a team as a code owner April 11, 2025 10:12
@bmarty bmarty requested review from jmartinesp and removed request for a team April 11, 2025 10:12
@bmarty bmarty added the Z-NextRelease For issues and PRs which should be included in the NextRelease. label Apr 11, 2025
Copy link
Contributor

github-actions bot commented Apr 11, 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/uMsU5C

Copy link

codecov bot commented Apr 11, 2025

Codecov Report

Attention: Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.

Project coverage is 80.06%. Comparing base (2b1a66f) to head (8015668).
Report is 13 commits behind head on develop.

Files with missing lines Patch % Lines
...ures/invite/impl/DefaultSeenInvitesStoreFactory.kt 0.00% 11 Missing ⚠️
...nt/android/features/invite/impl/di/InviteModule.kt 0.00% 3 Missing ⚠️
...id/features/invite/impl/DefaultSeenInvitesStore.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4577      +/-   ##
===========================================
- Coverage    80.08%   80.06%   -0.02%     
===========================================
  Files         2087     2089       +2     
  Lines        55121    55134      +13     
  Branches      6876     6876              
===========================================
  Hits         44144    44144              
- Misses        8617     8630      +13     
  Partials      2360     2360              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

Thanks I can confirm it fixes the issue for me!

Comment on lines 40 to 43
private val seenInvitesStore = seenInvitesStoreFactory.getOrCreate(
sessionId = client.sessionId,
sessionCoroutineScope = client.sessionCoroutineScope,
)
Copy link
Member

Choose a reason for hiding this comment

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

I don't mind using this, but I think you could also create a @Provides method for SessionScope that would return the cached store if needed:

@Provides
fun providesSeenInvitesStore(factory: SeenInvitesStoreFactory, sessionId: SessionId, @SessionCoroutineScope sessionCoroutineScope: CoroutineScope) {
    return factory.getOrCreate(sessionId, sesionCoroutineScope)
 }

And then you can just inject the result in the session scope.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah that's a bit cleaner, will give it a try

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link

@bmarty bmarty enabled auto-merge (squash) April 11, 2025 13:25
@bmarty bmarty merged commit 91b7617 into develop Apr 11, 2025
29 checks passed
@bmarty bmarty deleted the feature/bma/fixStoreCrash branch April 11, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Bugfix For bug fix Z-NextRelease For issues and PRs which should be included in the NextRelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The app crashes under certain conditions.
2 participants