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

fix(coroutine) : make sure to switch coroutine context #4146

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

ganfra
Copy link
Member

@ganfra ganfra commented Jan 14, 2025

Content

Make sure to switch coroutine context as rust sdk is not safe to use on main thread.

Motivation and context

Fix ANRs and make sure code is safe to use from main thread under any circumstance.
Replaces #4133

Tests

  • Step 1
  • Step 2
  • Step ...

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

@ganfra ganfra added the PR-Bugfix For bug fix label Jan 14, 2025
Copy link
Contributor

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

Copy link

codecov bot commented Jan 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.26%. Comparing base (c7dbc7a) to head (331f692).
Report is 19 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4146   +/-   ##
========================================
  Coverage    83.26%   83.26%           
========================================
  Files         1885     1885           
  Lines        49127    49127           
  Branches      5774     5774           
========================================
  Hits         40907    40907           
  Misses        6144     6144           
  Partials      2076     2076           

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

@ganfra ganfra marked this pull request as ready for review January 14, 2025 15:22
@ganfra ganfra requested a review from a team as a code owner January 14, 2025 15:22
@ganfra ganfra requested review from bmarty and removed request for a team January 14, 2025 15:22
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.

Thanks!

}
},
)
}
Copy link
Member

Choose a reason for hiding this comment

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

There is no change here, just to confirm.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, the method is not suspending

override suspend fun canUserInvite(userId: UserId): Result<Boolean> {
return runCatching {
override suspend fun canUserInvite(userId: UserId): Result<Boolean> = withContext(roomDispatcher) {
runCatching {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe introduce an extension like

    suspend fun <T> CoroutineContext.invokeInner(block: suspend () -> T): Result<T> = withContext(this) {
        runCatching {
            block()
        }
    }

(with a better name...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe later, but I'm not convinced this is necessary...

@ganfra ganfra merged commit 0d63610 into develop Jan 15, 2025
30 checks passed
@ganfra ganfra deleted the feature/fga/suspend_unsafe_sdk_method branch January 15, 2025 10:50
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