realm-kotlin icon indicating copy to clipboard operation
realm-kotlin copied to clipboard

Capture and throw uncaught C++ exception

Open nhachicha opened this issue 4 years ago • 2 comments

Some exceptions were thrown from C++ without being captured and re-thrown, this can cause undefined behaviour for subsequent native calls/callbacks. We should also check jenv->ExceptionCheck() from JNI before invoking Java in case there's a pending exception lingering

Example

-  09-21 10:08:21.288 16105 16132 E REALM   : uncaught exception in notifier thread: N5realm24IncorrectThreadExceptionE: Realm accessed from incorrect thread./data/user/0/io.realm.testapp.test/files/realm1
- 09-21 10:08:21.288 16105 16132 E libc++abi: terminating with uncaught exception of type realm::IncorrectThreadException: Realm accessed from incorrect thread./data/user/0/io.realm.testapp.test/files/realm1
- 09-21 10:08:21.288 16105 16132 F libc    : Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 16132 (Thread-3), pid 16105 (lm.testapp.test)
- ```

nhachicha avatar Sep 22 '21 17:09 nhachicha

This is especially problematic in cases where a strategy pattern in ObjectStore is calling Java multiple times. I recently fixed a bug in the Java notifier around this.

cmelchior avatar Sep 22 '21 18:09 cmelchior

Hi @cmelchior, could you please share with me how to fix this issue? I also experienced same issues for realm random crashes with Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) when use realm-kotlin. This issue happen on Huawei, Xiaomi, Nokia and some other devices in the scenario that I kill app and re-open the app instantly.

thuannv avatar Jul 05 '22 09:07 thuannv