question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

N5realm10InvalidKeyE Exception on older Androids and emulators

See original GitHub issue

Goals

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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Shumuucommented, Mar 6, 2020

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.

0reactions
hieu-htcommented, Apr 28, 2020

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 ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot known issues with Android Emulator
This page lists known issues, workarounds, and troubleshooting tips for the Android Emulator. If you encounter an issue not listed here or ...
Read more >
AVD Emulator not working anymore on Bumblebee #76 - GitHub
I just updated Android Studio to Bumblebee and I really REGRET it. Emulator doesn't work anymore Whenever I launch it they just get...
Read more >
Android Emulator Troubleshooting - .NET MAUI | Microsoft Learn
This article describes the most common warning messages and issues that occur while configuring and running the Android Emulator.
Read more >
Exception 'open failed - EACCES (Permission denied)
If you are trying on the emulator then from android 6.0 onwards you need to explicitly go the settings->apps-> YOURAPP -> permissions and...
Read more >
Turn An Old Android Phone Into A Gaming & Emulation ...
FindTurn an older Android phone into an awesome Gaming/ Emulation home console!In this video, we take an older Essential Phone PH1 that I ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found