-
Notifications
You must be signed in to change notification settings - Fork 731
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
Avoid accessing realm instance from suspend functions #5592
Avoid accessing realm instance from suspend functions #5592
Conversation
…cessing the realm instance (thread local)
@@ -101,9 +101,7 @@ internal class TimelineEventDecryptor @Inject constructor( | |||
executor?.execute { | |||
Realm.getInstance(realmConfiguration).use { realm -> | |||
try { | |||
runBlocking { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the aim is to ensure the realm instance is only executed on a single thread it might be safer to keep the runBlocking
here next to the instance creation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to avoid making the function processDecryptRequest
suspended. However, I can see the benefit you describe.
it's a bit tricky to tell from the diff, where does the thread jumping happen? I was expecting to see a |
From my understanding without |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just wrap cryptoService.decryptEvent(XXX) with runBlocking instead of whole functions
…nd_functions # Conflicts: # matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineEventDecryptor.kt # matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/RoomSyncHandler.kt
Add runBlocking when decrypt events to avoid thread switching when accessing the realm instance (thread local)