-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix notification exceptions not getting correctly detected in JNI #7559
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
Conversation
… thus causing native crashes when accessing the JNIEnv. Refactor RealmNotifier tests to use the BlockingLooperThread class.
rorbech
left a comment
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.
Is adding these ExceptionChecks sufficient? Shouldn't it rather be handling this on backside of the actual call throwing the exception? But, I it is a big improvement and with tests verifying that it does the right thing for the notification callbacks I guess it LGTM.
The BindingContext is being called from C++ that doesn't understand Java exceptions. In this case, it has a flow where it calls back and forth 3-4 times. Right now there is no way to signal errors in this path, so we need to shortcut all the steps. |
Attempt another work-around to close session with Realm
…ms with Core 11.4.0.
| { | ||
| try { | ||
| auto& config = *reinterpret_cast<Realm::Config*>(j_native_config_ptr); | ||
| _impl::RealmCoordinator::get_coordinator(config)->create_session(config); |
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.
where is the session created now?
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.
It is created automatically by Object Store when you open the Realm.
This PR fixes an issue where crashes inside background change listeners would not get correctly detected, thus crashing the JavaBindingContext in unrelated ways when accessing the JNIEnv.
Sending notifications on background looper threads involves a number of callbacks from and to JNI and each of these steps needs a guard against this. It isn't possible to test for each specific callback, so I just added a test for the most important one: Exceptions inside the actual callback.
This case was detected when using coroutines with a custom looper Dispatcher. Canceling the scope would result in a
CoroutineExceptioninside the callback, but instead of the "real" exception people would seeJNI DETECTED ERROR IN APPLICATION: JNI NewLocalRef called with pending exception kotlinx.coroutines.JobCancellationException: Job was cancelledin unrelated code.