realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.8k stars 577 forks source link

Segmentation fault / segfault in react-native #3084

Closed jdegger closed 4 years ago

jdegger commented 4 years ago

Goals

Run Realm as stable as possible

Expected Results

No segfaults

Actual Results

Segfaults

OS Version: Android 10 (POT-LX1 10.0.0.166(C431E3R2P3))
Report Version: 104

Exception Type: Unknown (SIGSEGV)

Application Specific Information:
Segfault

Thread 0 Crashed:
0   libjsc.so                       0x754793ea7c        <unknown> + 503712049788
1   libjsc.so                       0x754755cffc        JSValueUnprotect
2   librealmreact.so                0x752b07e200        <unknown> + 503233110528
3   librealmreact.so                0x752b070f30        <unknown> + 503233056560
4   librealmreact.so                0x752b1c27d4        <unknown> + 503234439124
5   librealmreact.so                0x752b1c2538        <unknown> + 503234438456
6   librealmreact.so                0x752b1ef588        <unknown> + 503234622856
7   librealmreact.so                0x752b063138        <unknown> + 503232999736
8   librealmreact.so                0x752b1d6d3c        Java_io_realm_react_RealmReactModule_setupChromeDebugModeRealmJsContext
9   base.odex                       0x755523e470        <unknown> + 503939589232

Steps to Reproduce

I wish I could give you reproduction steps. I'm sharing this issue to check if others encounter this problem and if there are any pointes as to where this is coming frmo.

Code Sample

n/a

Version of Realm and Tooling

Realm: 6.0.3 React Native: 0.63.1 Device:

Key Value
Architecture arm64-v8a
Architectures [arm64v8a, armeabiv7a, armeabi]
Battery Level 100%
Boot Time 20200721T09:24:33.143Z
Brand HUAWEI
Charging True
Connection Type wifi
Family POT-LX1
Free Memory 1131655168
Free Storage 47972577280
Id 3d8412176b72ed02
Language en_NL
Low Memory False
Manufacturer HUAWEI
Memory Size 2819547136
Model POTLX1 (HUAWEIPOTL21)
Model Id HUAWEIPOT-L21
Name POT-LX1
Online True
Orientation portrait
Screen Density 3
Screen DPI 480
Screen Height Pixels 2139
Screen Resolution 2139x1080
Screen Width Pixels 1080
Simulator False
Storage Size 55652122624
Timezone Europe/Amsterdam
jdegger commented 4 years ago

@Contributors: let me know how I can give more information about this problem.

handipriyono commented 4 years ago

Hi @jdegger , i also got same issue.. my react native app crash when it comes to use realm js.

Screen Shot 2020-07-31 at 11 54 47 PM

my device info:

Screen Shot 2020-07-31 at 11 59 53 PM
handipriyono commented 4 years ago

@contributors: let me know how I can give more information about this problem.

please keep updated about this problem , bro. No idea of how to solve it till now.

ivangr1 commented 4 years ago

It happens to me also, my React Native app is in production and I have almost 3-4 crash reports of librealmreact.so from Play Console everyday.

It happens in almost every version of Android and every smartphone model but I seems to be more often on Android 9.0 and 6.0 and Samsung and Huawei phones

I am able to reproduce it on my Pixel 2 XL (Android 10), but it is not consistent, it happens when I quickly switch screens from one to another back and forth, sometimes it crashes on the third switch, sometimes on the 10th but it will crash eventually. I am using react-navigation and the screen that I am switching to is opening a new Realm inside `componentDidMount' callback, so maybe this has something to do with it.

This is my stacktrace, not very intuitive:

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR)
librealmreact.so
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 0 >>> com.myapp <<<

backtrace:
  #00  pc 00000000001d56d8  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001d5570  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001d11f4  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001d0194  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001cfc20  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001ce5bc  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001fa534  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001fa2a4  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001f9dd8  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001f9bec  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001f9b80  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001f9acc  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001bc608  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001bdf8c  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000000b4d7c  /data/data/com.myapp/lib-0/libjsc.so
douglasndm commented 4 years ago

I have the same problems with my production build.

React Native 0.63.2 Realm 6.0.4

Screenshot (191) Screenshot (192)

jdegger commented 4 years ago

I think it seems clear that I'm not the only one experiencing this problem. However, I can imagine that the maintainers of Realm can't resolve this issue with the information currently provided.

@tgoyne @kneth @blagoev how can we give you the information you need to resolve this problem? Or do you think that this is not a realm problem?

kneth commented 4 years ago

Sorry for the late reply. We need to investigate it. Did you observe similar crashes with earlier versions in the 6.0.x series? With v6.0.0 we upgraded Android NDK, and I wonder if that broke some assumption we did about C++ compilers.

douglasndm commented 4 years ago

I have never used Realm before 6.0 so I can't answer this, but I have some more logs from pre-lauch report from Google Play, maybe can be useful

`Build: samsung/m0xx/m0:4.3/JSS15J/I9300XXUGMK6:user/release-keys Hardware: smdk4x12 Revision: 12 Bootloader: I9300ZCUBML1 Radio: unknown Kernel: Linux version 3.0.31-2191747 (dpi@DELL136) (gcc version 4.4.3 (GCC) ) #1 SMP PREEMPT Tue Nov 26 16:57:12 KST 2013


Build fingerprint: 'samsung/m0xx/m0:4.3/JSS15J/I9300XXUGMK6:user/release-keys' Revision: '12' pid: 13450, tid: 13450, name: pool-34-thread- >>> com.controledevalidade <<< signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad Abort message: '/Volumes/Android/buildbot/src/android/ndk-release-r21/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:72: abort_message: assertion "terminating" failed' r0 00000027 r1 00000000 r2 00000008 r3 deadbaad r4 00000000 r5 691ff294 r6 66fd8bbb r7 691ff71c r8 00001000 r9 00000000 sl 4019389c fp 0000000c ip 4014ebe7 sp 691ff290 lr 4015d2ff pc 4015a824 cpsr 60000030 d0 0000000000000000 d1 0000000000000000 d2 0000000000000000 d3 0000000000000001 d4 4000000000000316 d5 000003fc40000000 d6 0000018b43c58000 d7 11449dd54499c000 d8 0000000000000000 d9 0000000000000000 d10 0000000000000000 d11 0000000000000000 d12 0000000000000000 d13 0000000000000000 d14 0000000000000000 d15 0000000000000000 d16 0000000000000000 d17 0000000000000000 d18 3dea39ef35793c76 d19 0065004e005f0061 d20 3f8948b0fcd6e9e0 d21 3ff0000000000000 d22 3fd24998d6307188 d23 3fcc7288e957b53b d24 3fc74721cad6b0ed d25 3fc2f112df3e5244 d26 3fe62e42fefa39ef d27 4000000000000000 d28 40008df2d49d41f1 d29 3fb0f4a31edab38b d30 3ff0000000000000 d31 3f4de16b9c24a98f scr 60000011 backtrace:

00 pc 0001e824 /system/lib/libc.so

#01  pc 0001c76c  /system/lib/libc.so (abort+4)
#02  pc 000122ed  /system/lib/libc.so
#03  pc 000117fd  /system/lib/libc.so (__assert2+20)
#04  pc 005abb47  /data/app-lib/com.controledevalidade-1/librealmreact.so
#05  pc 005abbcf  /data/app-lib/com.controledevalidade-1/librealmreact.so
#06  pc 005aa1e9  /data/app-lib/com.controledevalidade-1/librealmreact.so

stack: 691ff250 00000000
691ff254 00000000
691ff258 40184170 /system/lib/libc.so 691ff25c 41b9abe0
691ff260 40184170 /system/lib/libc.so 691ff264 4015c2ad /system/lib/libc.so (__sflush+56) 691ff268 40184264 /system/lib/libc.so 691ff26c 401841c4 /system/lib/libc.so 691ff270 ffffffff
691ff274 4015d2ff /system/lib/libc.so (_fwalk+34) 691ff278 4015c5a9 /system/lib/libc.so (_cleanup) 691ff27c 691ff294
691ff280 66fd8bbb /data/app-lib/com.controledevalidade-1/librealmreact.so 691ff284 691ff71c
691ff288 df0027ad
691ff28c 00000000

00 691ff290 40187204

     691ff294  fffffbdf  
     691ff298  5b3f4000  
     691ff29c  000000ab  
     691ff2a0  ffffffff  
     691ff2a4  00000000  
     691ff2a8  00000003  
     691ff2ac  691ff2d4  
     691ff2b0  00000048  
     691ff2b4  40158770  /system/lib/libc.so (__pthread_clone)
#01  691ff2b8  00000000  
     691ff2bc  4014e2f1  /system/lib/libc.so
#02  691ff2c0  691ff6e4  
     691ff2c4  000000a6  
     691ff2c8  691ff2d4  
     691ff2cc  691ff37a  
     691ff2d0  691ff6d3  
     691ff2d4  6c6f562f  
     691ff2d8  73656d75  
     691ff2dc  646e412f  
     691ff2e0  64696f72  
     691ff2e4  6975622f  
     691ff2e8  6f62646c  
     691ff2ec  72732f74  
     691ff2f0  6e612f63  
     691ff2f4  696f7264  
     691ff2f8  646e2f64  
     691ff2fc  65722d6b  
     ........  ........
#03  691ff6f0  5b79d608  
     691ff6f4  00000048  
     691ff6f8  66fd8c30  /data/app-lib/com.controledevalidade-1/librealmreact.so
     691ff6fc  66eaab4b  /data/app-lib/com.controledevalidade-1/librealmreact.so

processName:com.controledevalidade broadcastEvent : com.controledevalidade SYSTEM_TOMBSTONE`

jdegger commented 4 years ago

@kneth

Sorry for the late reply. We need to investigate it. Did you observe similar crashes with earlier versions in the 6.0.x series? With v6.0.0 we upgraded Android NDK, and I wonder if that broke some assumption we did about C++ compilers.

We came from 2.29.2 and never encountered any problems. The big jump in version is because of some incompatibilities we had between different packages.

ivangr1 commented 4 years ago

It happens to me also, my React Native app is in production and I have almost 3-4 crash reports of librealmreact.so from Play Console everyday.

It happens in almost every version of Android and every smartphone model but I seems to be more often on Android 9.0 and 6.0 and Samsung and Huawei phones

I am able to reproduce it on my Pixel 2 XL (Android 10), but it is not consistent, it happens when I quickly switch screens from one to another back and forth, sometimes it crashes on the third switch, sometimes on the 10th but it will crash eventually. I am using react-navigation and the screen that I am switching to is opening a new Realm inside `componentDidMount' callback, so maybe this has something to do with it.

  • "realm": "^6.0.3",
  • "react-native": "0.63.2"

This is my stacktrace, not very intuitive:

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR)
librealmreact.so
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 0 >>> com.myapp <<<

backtrace:
  #00  pc 00000000001d56d8  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001d5570  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001d11f4  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001d0194  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001cfc20  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001ce5bc  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001fa534  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001fa2a4  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001f9dd8  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001f9bec  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001f9b80  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001f9acc  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001bc608  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000001bdf8c  /data/data/com.myapp/lib-0/librealmreact.so
  #00  pc 00000000000b4d7c  /data/data/com.myapp/lib-0/libjsc.so

UPDATE: My issues seem to be almost completely resolved in version 6.0.4 I updated many components in my project at the same time, including Realm (from 6.0.3 to 6.0.4) so I don't know if it had to do with some other component, but the crash was caused by librealmreact.so so I guess the Realm update did something.

I still got three crashes on Android 10 on Huawei P20 and Mate 20 Pro and Galaxy A40 in 5 days, but that's much better than 5-6 crashes every day

kneth commented 4 years ago

@ivangr1 Thanks for the update. Just to be sure: do you only see the crashes on Android 10?

Thierry-Santos commented 4 years ago

It happens to me also, most part of the time is on this function...

export default function getRealm() {
  return Realm.open({
    schema: schemaArray,
    schemaVersion: buildVersion,
  });
}

export const getProductsAndCategories = async (selectedCategory, sector) => {
  try {
    const realm = await getRealm();
    const categories = realm
      .objects('Category')
      .filtered(
        `type_category = "${selectedCategory}" and sector = "${sector}"`,
      );

    const listProducts = await Promise.all(
      categories.map(item =>
        Promise.resolve({
          id: item.id,
          name: item.name,
          product: realm
            .objects('EstabilishmentProduct')
            .filtered(epQueryHandler(item.id, sector))
            .sorted(['price', 'offer_price'])
            .slice(0, 20)
        })
      )
    );

    return listProducts;
  } catch (e) {
    console.log('getProductsAndCategories', e);
  }
};
ivangr1 commented 4 years ago

@ivangr1 Thanks for the update. Just to be sure: do you only see the crashes on Android 10?

Correct, that's the info I got from Play Console. But, in the meantime I managed to get one crash on my old HTC Desire with Android 6.0.1 while debugging.

I don't know if my issue is connected with the other ones, but for me 6.0.4 update definitely did something to fix the crashes

JuanCamilo0809 commented 4 years ago

Hi, any solution for this issue, i have the same problem

"react": "16.9.0", "react-native": "0.61.5", "realm": "^6.0.4"

OS Version: Android 7.1.1 (M60WL_V2.02) Report Version: 104

Exception Type: Unknown (SIGSEGV)

Application Specific Information: Segfault

Thread 0 Crashed: 0 librealmreact.so 0x7f7e049f98 0x7f7de71000 + 547575078808 1 librealmreact.so 0x7f7e049e34 0x7f7de71000 + 547575078452 2 librealmreact.so 0x7f7e045ab8 0x7f7de71000 + 547575061176 3 librealmreact.so 0x7f7e044a58 0x7f7de71000 + 547575056984 4 librealmreact.so 0x7f7e0444e4 0x7f7de71000 + 547575055588 5 librealmreact.so 0x7f7e042e80 0x7f7de71000 + 547575049856 6 librealmreact.so 0x7f7e0ff78c 0x7f7de71000 + 547575822220 7 librealmreact.so 0x7f7e0a8784 0x7f7de71000 + 547575465860 8 libjsc.so 0x7f7eedfb40 0x7f7ee2c000 + 547590372160 9 0x7f758ff02c 0x0

RealmBot commented 4 years ago

➤ Finn Andersen commented:

I can't help but noting that the faulting address is "deadbaad" .... which could be a clue. Unfortunately it's not a clue to me. That constant is not in use in the part of Realm code, I'm familiar with. Could also just be a coincidence.

douglasndm commented 4 years ago

Hi guys.

I've had search a lot and maybe I found a fix. Some people say this is relating to react native screens and I found this comment/Stackoverflow and I did it and until now it works for me. I'm not experienced yet so I don't know how RN Screens makes crashes on Realm but I put my code with those fixes in production and I didn't get any other error yet.

I'm still analyzing Sentry and Firebase crashes logs and I will let you know if something change;

kneth commented 4 years ago

@douglasndm Thank you for your update.

@JuanCamilo0809 @ivangr1 @handipriyono @jdegger Is it possible for you to try the proposed fix? If it doesn't solve it for you, we would like to know more of the circumstances when the crash happen. For example, it is when you open the app? Or has the app been running for a while? Is the Realm file small or large? Without a repro case, we need to investigate more and answering these questions might help us.

JuanCamilo0809 commented 4 years ago

Hi,

@douglasndm, I fixed this issue!!!!

The problem was because I was creating one connection in wich component, I change and create only one connection and I pass this connection for propierties a other component and... Boommmm

All its OK!!

Thanks for all!!!

geragray commented 4 years ago

@JuanCamilo0809 thanks for letting up know! I am closing this issue.

ruelpaquera commented 2 years ago

Hi,

@douglasndm, I fixed this issue!!!!

The problem was because I was creating one connection in wich component, I change and create only one connection and I pass this connection for propierties a other component and... Boommmm

All its OK!!

Thanks for all!!!

i also did this. did you keep your code? or you changing it?