N5realm10InvalidKeyE Exception on older Androids and emulators
See original GitHub issueGoals
We have a chat app that uses Realm to store groups and messages. It works fine on iOS and new Android 10 devices, but crashes on Android 8 and some 9 devices and all emulators with E/REALM: uncaught exception in notifier thread: N5realm10InvalidKeyE: Key not found. We obviously doing something wrong. If it will not be obvious from the code - could you provide some guidance to why this error can happen?
Expected Results
App working flawlessly on all devices
Actual Results
2020-02-07 03:44:08.830 31353-31459/com.tyrion.debug E/REALM: uncaught exception in notifier thread: N5realm10InvalidKeyE: Key not found
2020-02-07 03:44:08.934 31475-31475/? I/crash_dump32: obtaining output fd from tombstoned, type: kDebuggerdTombstone
2020-02-07 03:44:08.941 1798-2475/? E/GnssHAL_GnssInterface: gnssSvStatusCb: a: input svInfo.flags is 8
2020-02-07 03:44:08.941 1798-2475/? E/GnssHAL_GnssInterface: gnssSvStatusCb: b: input svInfo.flags is 8
2020-02-07 03:44:08.941 1877-1877/? I//system/bin/tombstoned: received crash request for pid 31459
2020-02-07 03:44:08.945 31475-31475/? I/crash_dump32: performing dump of process 31353 (target tid = 31459)
2020-02-07 03:44:08.955 31475-31475/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2020-02-07 03:44:08.955 31475-31475/? A/DEBUG: Build fingerprint: 'google/sdk_gphone_x86/generic_x86:10/QSR1.191030.002/5978551:userdebug/dev-keys'
2020-02-07 03:44:08.956 31475-31475/? A/DEBUG: Revision: '0'
2020-02-07 03:44:08.956 31475-31475/? A/DEBUG: ABI: 'x86'
2020-02-07 03:44:08.956 31475-31475/? A/DEBUG: Timestamp: 2020-02-07 03:44:08+0200
2020-02-07 03:44:08.956 31475-31475/? A/DEBUG: pid: 31353, tid: 31459, name: mqt_js >>> com.tyrion.debug <<<
2020-02-07 03:44:08.956 31475-31475/? A/DEBUG: uid: 10151
2020-02-07 03:44:08.956 31475-31475/? A/DEBUG: signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
2020-02-07 03:44:08.957 31475-31475/? A/DEBUG: eax 00000000 ebx 00007a79 ecx 00007ae3 edx 00000006
2020-02-07 03:44:08.957 31475-31475/? A/DEBUG: edi f018633e esi c1144050
2020-02-07 03:44:08.957 31475-31475/? A/DEBUG: ebp f15f0ad0 esp c1143ff8 eip f15f0ad9
2020-02-07 03:44:08.961 31475-31475/? A/DEBUG: backtrace:
2020-02-07 03:44:08.961 31475-31475/? A/DEBUG: #00 pc 00000ad9 [vdso] (__kernel_vsyscall+9)
2020-02-07 03:44:08.961 31475-31475/? A/DEBUG: #01 pc 00092328 /apex/com.android.runtime/lib/bionic/libc.so (syscall+40) (BuildId: 76290498408016ad14f4b98c3ab6c65c)
2020-02-07 03:44:08.961 31475-31475/? A/DEBUG: #02 pc 000ad651 /apex/com.android.runtime/lib/bionic/libc.so (abort+193) (BuildId: 76290498408016ad14f4b98c3ab6c65c)
2020-02-07 03:44:08.961 31475-31475/? A/DEBUG: #03 pc 00706094 /data/app/com.tyrion.debug-t73KkKy41_jbPxwoNLqbdg==/lib/x86/librealmreact.so (__gnu_cxx::__verbose_terminate_handler()+452) (BuildId: d0d6f5f7cdee87842f0efd79695e74cbfc1ec204)
2020-02-07 03:44:08.961 31475-31475/? A/DEBUG: #04 pc 006a8fa7 /data/app/com.tyrion.debug-t73KkKy41_jbPxwoNLqbdg==/lib/x86/librealmreact.so (__cxxabiv1::__terminate(void (*)())+23) (BuildId: d0d6f5f7cdee87842f0efd79695e74cbfc1ec204)
2020-02-07 03:44:08.961 31475-31475/? A/DEBUG: #05 pc 006a903f /data/app/com.tyrion.debug-t73KkKy41_jbPxwoNLqbdg==/lib/x86/librealmreact.so (std::terminate()+31) (BuildId: d0d6f5f7cdee87842f0efd79695e74cbfc1ec204)
2020-02-07 03:44:08.962 31475-31475/? A/DEBUG: #06 pc 00701b8d /data/app/com.tyrion.debug-t73KkKy41_jbPxwoNLqbdg==/lib/x86/librealmreact.so (BuildId: d0d6f5f7cdee87842f0efd79695e74cbfc1ec204)
2020-02-07 03:44:08.962 31475-31475/? A/DEBUG: #07 pc 0011a8e5 /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+53) (BuildId: 76290498408016ad14f4b98c3ab6c65c)
2020-02-07 03:44:08.962 31475-31475/? A/DEBUG: #08 pc 000af6a7 /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71) (BuildId: 76290498408016ad14f4b98c3ab6c65c)
2020-02-07 03:44:09.291 1952-1952/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
Steps to Reproduce
We have one Realm instance open on app startup and closed at app end. It is mainly used for read and subscription to objects.
We then create a new instance for every write transaction (see the code below) and closing it when write is done. We tried to use the above instance for everything but then the crash is almost immediate. In the second scenario, it happens after writing several objects. We have actions happening on both Main Thread and JS thread.
Code Sample
write = <T = any>(transaction: () => T): T => {
let returnable: T;
const id = new Date().getTime();
const realm = new Realm(this.realmParams);
try {
realm.beginTransaction();
returnable = transaction(realm);
realm.commitTransaction();
console.log("AFTER COMMIT", id);
} catch (error) {
console.log("CANCEL TRANSACTION", id);
realm.cancelTransaction();
throw new Error(error);
}
let entity;
if (returnable?.id) {
entity = realm.objectForPrimaryKey(returnable.name, returnable.id);
}
if (!realm?.isClosed) {
realm.close();
}
return entity;
};
Transactions are:
let entity = (realm.create(
name,
params,
true,
) as unknown) as T;
if (name === 'Message') {
// @ts-ignore
if (params?.content) {
((entity as unknown) as Message).content = params?.content!;
}
if (params?.reactions === null) {
((entity as unknown) as Message).reactions = null;
}
if (params?.reactions) {
((entity as unknown) as Message).reactions = params?.reactions!;
}
} else if (name === 'Topic' && newMessagesCounter) {
((entity as unknown) as Topic).unreadCounter += newMessagesCounter;
}
return {name, id: params.id};
Version of Realm and Tooling
- Realm JS SDK Version: 0.61.5
- Node or React Native: RN
- Client OS & Version: Android 8,9
- Which debugger for React Native: None
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Today I got a lot of progress done and I was able to successfully attach a listener to my collection without crashing the Application. I’ll try to work out a small project but for now here are my observations.
When I removed all relations and only stored the primary key, I could listen without a problem. No crashes.
When I left the relations in but changed the primary key type from string to int, I could attach a listener.
Previously the collection had a primary key of string, which was generated by uuid. Just changing it to int works perfectly but it seems to be a combination of stored Relations AND primary key of string, since changing one of those fixes the problem.
Thanks, you save my life ❤️