react-native: SIGSEGV crash with ART library on Android

This issue is somewhat intermittent, but I have managed to create a minimal example that will crash with some regularity. When the ART library is used to render a component it seems it will cause a crash on Android after it has rendered several times. This issue happens looks to have started with React Native 0.21 and only happens on Android.

Unfortunately the crash happens deep in libc and tracing the cause of the issue has been difficult. The code below reproduces the issue on Android. It will sometimes crash quite quickly (within seconds) and sometimes takes a bit longer (tens of seconds) with an error in the log like:

A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x9fa40028 in tid 4388 (mqt_js)

import React, { Text, View } from 'react-native';
const { Surface, Group, Shape } = React.ART;

const Smiley = React.createClass({
  render() {
    return (
      <Surface width={32} height={32}>
        <Group scaleX={1} scaleY={1} rotation={this.props.rotation} originX={16} originY={16} opacity={this.props.opacity}>
          <Group>
            <Shape fill="#222" d="M16 .004 c-8.837 0 -16 7.164 -16 16 0 8.837 7.163 16 16 16 s16 -7.163 16 -16 c0 -8.836 -7.163 -16 -16 -16 z m0 29 c-7.16 0 -12.985 -5.832 -12.985 -13 s5.825 -13 12.985 -13 c7.16 0 12.985 5.832 12.985 13 s-5.825 13 -12.985 13 z"/>
            <Shape fill="#222" d="M7.932 12.77 A2.513 2.5 0 1 0 12.958 12.77 A2.513 2.5 0 1 0 7.932 12.77 z"/>
            <Shape fill="#222" d="M18.872 12.77 A2.513 2.5 0 1 0 23.898000000000003 12.77 A2.513 2.5 0 1 0 18.872 12.77 z"/>
            <Shape fill="#222" d="M24.054 18.39 a1.006 1.006 0 0 0 -.85 .01 c-.005 .004 -.01 .003 -.015 .006 l-.98 .506 c-.62 .278 -1.4 .664 -2.43 .992 -1.04 .328 -2.53 .503 -4.09 .575 -1.56 -.08 -3.05 -.25 -4.09 -.58 -1.04 -.33 -1.82 -.72 -2.43 -.99 l-.97 -.51 -.02 -.01 a1 1 0 0 0 -.85 -.01 .992 .992 0 0 0 -.5 1.32 c1.59 3.502 4.93 5.79 8.58 5.946 .05 .01 .5 .01 .552 0 3.65 -.16 6.99 -2.444 8.582 -5.946 a1 1 0 0 0 -.503 -1.322 z"/>
          </Group>
        </Group>
      </Surface>
    );
  },
});

class CrashTestDummy extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 0,
    };
  }

  componentDidMount() {
    setInterval(() => { this.state && this.setState({count: this.state.count + 1}) }, 20);
  }

  render() {
    return (
      <View style={{flex: 1, justifyContent: "center", alignItems: "center"}}>
        <Text>
          Count: {this.state.count}
        </Text>
        <Smiley/>
      </View>
    );
  }
}

React.AppRegistry.registerComponent('CrashTestDummy', () => CrashTestDummy);

I’ve noticed that when I use a more complex component that contains more ART elements, it crashes more quickly, suggesting a memory issue.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 29
  • Comments: 49 (16 by maintainers)

Most upvoted comments

Did anyone find any workaround or solution to this? I am facing the same issue.

We see this too. A lot in debug mode. From the dumps, it looks like a crash on the JSC (JavaScriptCore) execution thread.

I started thinking in terms of building a debug version of JSC to see if we could get more information. What I found wasn’t entirely encouraging. The JSC build used in React Native seems to come from here:

https://github.com/facebook/android-jsc

and is only buildable with Buck out of the box. I also looked to see which version of JSC it was based on. In fetch_sources.sh it grabs:

http://builds.nightly.webkit.org/files/trunk/src/WebKit-r174650.tar.bz2

I searched for that version here:

https://webkit.org/nightly/archives/

and the timestamp on it is: October 14, 2014 1:09 PM GMT.

I would suggest that the dependence of React Native for Android on an 18 month old (and counting) snapshot of JSC should be of some concern to us all.

still get this issue, I have try 3 diff android emulator, on Nexus 4 API 22, it is just work fine, on Nexus 5X API 23, it crash!!! on Nexus 6 API P, it is work fine too.

RN Version: 0.55.2

crash logs:

05-05 13:26:37.554 3331-3331/com.elecirc.MobiNG A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0xd5dc8000 in tid 3331 (.elecirc.MobiNG)
05-05 13:26:37.556 3331-3356/com.elecirc.MobiNG A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xbbadbeef in tid 3356 (mqt_js)
05-05 13:26:37.656 1324-1324/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
05-05 13:26:37.656 1324-1324/? A/DEBUG: Build fingerprint: 'Android/sdk_google_phone_x86_64/generic_x86_64:6.0/MASTER/4660549:userdebug/test-keys'
05-05 13:26:37.656 1324-1324/? A/DEBUG: Revision: '0'
05-05 13:26:37.656 1324-1324/? A/DEBUG: ABI: 'x86'
05-05 13:26:37.656 1324-1324/? A/DEBUG: pid: 3331, tid: 3331, name: .elecirc.MobiNG  >>> com.elecirc.MobiNG <<<
05-05 13:26:37.656 1324-1324/? A/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xd5dc8000
05-05 13:26:37.661 1324-1324/? A/DEBUG:     eax 000b4200  ebx ea1deeb4  ecx 00027080  edx f40be0bc
05-05 13:26:37.661 1324-1324/? A/DEBUG:     esi d4c81000  edi d5dc8000
05-05 13:26:37.661 1324-1324/? A/DEBUG:     xcs 00000023  xds 0000002b  xes 0000002b  xfs 00000007  xss 0000002b
05-05 13:26:37.661 1324-1324/? A/DEBUG:     eip ea1d8a38  ebp 003fffc4  esp ffec5204  flags 00210202
05-05 13:26:37.667 1324-1324/? A/DEBUG: backtrace:
05-05 13:26:37.667 1324-1324/? A/DEBUG:     #00 pc 00002a38  /system/lib/libOpenglSystemCommon.so (goldfish_dma_write(goldfish_dma_context*, void*, unsigned int)+56)
05-05 13:26:37.667 1324-1324/? A/DEBUG:     #01 pc 00003853  /system/lib/libOpenglSystemCommon.so (ExtendedRCEncoderContext::lockAndWriteDma(void*, unsigned int)+67)
05-05 13:26:37.667 1324-1324/? A/DEBUG:     #02 pc 00003062  /system/lib/lib_renderControl_enc.so
05-05 13:26:37.667 1324-1324/? A/DEBUG:     #03 pc 0000314e  /system/lib/hw/gralloc.ranchu.so
05-05 13:26:37.667 1324-1324/? A/DEBUG:     #04 pc 0000a351  /system/lib/libui.so (android::GraphicBufferMapper::unlockAsync(native_handle const*, int*)+113)
05-05 13:26:37.667 1324-1324/? A/DEBUG:     #05 pc 000086f1  /system/lib/libui.so (android::GraphicBuffer::unlockAsync(int*)+49)
05-05 13:26:37.667 1324-1324/? A/DEBUG:     #06 pc 0006bae6  /system/lib/libgui.so (android::Surface::unlockAndPost()+70)
05-05 13:26:37.667 1324-1324/? A/DEBUG:     #07 pc 000b6b00  /system/lib/libandroid_runtime.so
05-05 13:26:37.667 1324-1324/? A/DEBUG:     #08 pc 73827746  /data/dalvik-cache/x86/system@framework@boot.oat (offset 0x1eb2000)

The issue still persists! Any help would be appreciated.

I am still meeting with this problem on 0.44.2.

Today I upgrade the version of react-native from 0.41.2 to 0.44.2, along with the react module version to 16.0.0-alpha.6. The app runs well at first, but it suddenly starts crashing and can never get started.

I have tried set android:largeHeap="true", but it does not help. I am testing my app on emulator, I don’t know whether platform is related or not. Here is my log:

05-29 17:45:52.584  7152  7182 F libc    : Fatal signal 11 (SIGSEGV), code 2, fault addr 0xa01af000 in tid 7182 (mqt_js)
05-29 17:45:52.688  1198  1198 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
05-29 17:45:52.688  1198  1198 F DEBUG   : Build fingerprint: 'Android/sdk_google_phone_x86/generic_x86:6.0/MASTER/2872745:userdebug/test-keys'
05-29 17:45:52.688  1198  1198 F DEBUG   : Revision: '0'
05-29 17:45:52.688  1198  1198 F DEBUG   : ABI: 'x86'
05-29 17:45:52.688  1198  1198 F DEBUG   : pid: 7152, tid: 7182, name: mqt_js  >>> com.mozidev.ouch <<<
05-29 17:45:52.688  1198  1198 F DEBUG   : signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xa01af000
05-29 17:45:52.693  1198  1198 F DEBUG   :     eax a01af000  ebx a0ba0d9c  ecx 00000000  edx a001c000
05-29 17:45:52.693  1198  1198 F DEBUG   :     esi ae513d80  edi a001c000
05-29 17:45:52.693  1198  1198 F DEBUG   :     xcs 00000073  xds 0000007b  xes 0000007b  xfs 000000b7  xss 0000007b
05-29 17:45:52.693  1198  1198 F DEBUG   :     eip b72b5620  ebp a05f3b70  esp a05f3b2c  flags 00210246
05-29 17:45:52.694  1198  1198 W debuggerd: type=1400 audit(0.0:36): avc: denied { search } for name="com.mozidev.ouch" dev="vdc" ino=21561 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
05-29 17:45:52.695  1198  1198 F DEBUG   : 
05-29 17:45:52.695  1198  1198 F DEBUG   : backtrace:
05-29 17:45:52.696  1198  1198 F DEBUG   :     #00 pc 0001e620  /system/lib/libc.so (strlen+496)
05-29 17:45:52.696  1198  1198 F DEBUG   :     #01 pc 00050305  /data/app/com.mozidev.ouch-2/lib/x86/libjsc.so (JSStringCreateWithUTF8CString+53)
05-29 17:45:52.696  1198  1198 F DEBUG   :     #02 pc 0006ad12  /data/app/com.mozidev.ouch-2/lib/x86/libreactnativejnifb.so (facebook::react::jsStringFromBigString(OpaqueJSContext const*, facebook::react::JSBigString const&)+98)
05-29 17:45:52.696  1198  1198 F DEBUG   :     #03 pc 0005c65b  /data/app/com.mozidev.ouch-2/lib/x86/libreactnativejnifb.so (facebook::react::JSCExecutor::loadApplicationScript(std::unique_ptr<facebook::react::JSBigString const, std::default_delete<facebook::react::JSBigString const> >, std::string)+203)
05-29 17:45:52.696  1198  1198 F DEBUG   :     #04 pc 000669e8  /data/app/com.mozidev.ouch-2/lib/x86/libreactnativejnifb.so
05-29 17:45:52.696  1198  1198 F DEBUG   :     #05 pc 00069d00  /data/app/com.mozidev.ouch-2/lib/x86/libreactnativejnifb.so
05-29 17:45:52.696  1198  1198 F DEBUG   :     #06 pc 00027370  /data/app/com.mozidev.ouch-2/lib/x86/libreactnativejnifb.so (std::function<void ()>::operator()() const+32)
05-29 17:45:52.698  1198  1198 F DEBUG   :     #07 pc 00028a81  /data/app/com.mozidev.ouch-2/lib/x86/libreactnativejnifb.so
05-29 17:45:52.698  1198  1198 F DEBUG   :     #08 pc 00015207  /data/app/com.mozidev.ouch-2/lib/x86/libreactnativejnifb.so
05-29 17:45:52.698  1198  1198 F DEBUG   :     #09 pc 00810b94  /data/app/com.mozidev.ouch-2/oat/x86/base.odex (offset 0x5ce000) (void com.facebook.react.bridge.queue.NativeRunnable.run()+104)
05-29 17:45:52.698  1198  1198 F DEBUG   :     #10 pc 72895c3b  /data/dalvik-cache/x86/system@framework@boot.oat (offset 0x1eb2000)
05-29 17:45:52.778  1198  1198 F DEBUG   : 
05-29 17:45:52.778  1198  1198 F DEBUG   : Tombstone written to: /data/tombstones/tombstone_05
05-29 17:45:52.778  1198  1198 E DEBUG   : AM write failed: Broken pipe
0

However, the release app runs well. 😦

Still getting crashes in the test repo above with RN 0.37

I put together a repo that reproduces the crash, just clone and npm install https://github.com/happypancake/animatedcrash

When we run it with JS Dev Mode turned on in an Android emulator, or an older device (Galaxy Nexus) it crashes reliably after 3-20 clicks on the heart. With JS Dev Mode off, my fingers got tired before any crashes. Same on a modern flagship phone with JS Dev Mode on, seemingly no crashes.

I am seeing a similar error message as well on Android: I am getting this: A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x4604b088 in tid 3316 (mqt_js) I am trying the same application on 2 different android versions:

  • On Samsung S6 with Android version 5.1.1, it crashes all the time at boot
  • On Nexus 5 with Android version 6.0, I could not see this issue.

The log output in the failing case:

logfailure.txt

Having the same problem when i render a big amount of svg’s.

React-Native v0.31 Samsung S5 mini, Android v5.1.1

I/art     (13459): Clamp target GC heap from 142MB to 128MB
I/art     (13459): Alloc partial concurrent mark sweep GC freed 8(256B) AllocSpace objects, 0(0B) LOS objects, 1% free, 126MB/128MB, paused 993us total 25.267ms
I/art     (13459): Clamp target GC heap from 142MB to 128MB
I/art     (13459): Alloc concurrent mark sweep GC freed 5(160B) AllocSpace objects, 0(0B) LOS objects, 1% free, 126MB/128MB, paused 1.106ms total 32.160ms
I/art     (13459): Forcing collection of SoftReferences for 1480KB allocation
I/art     (13459): Clamp target GC heap from 142MB to 128MB
I/art     (13459): Alloc concurrent mark sweep GC freed 4(128B) AllocSpace objects, 0(0B) LOS objects, 1% free, 126MB/128MB, paused 1.187ms total 31.849ms
E/art     (13459): Throwing OutOfMemoryError "Failed to allocate a 1516012 byte allocation with 1467240 free bytes and 1432KB until OOM"
E/AndroidRuntime(13459): FATAL EXCEPTION: mqt_native_modules
E/AndroidRuntime(13459): Process: com.MyApp, PID: 13459
E/AndroidRuntime(13459): java.lang.OutOfMemoryError: Failed to allocate a 1516012 byte allocation with 1467240 free bytes and 1432KB until OOM
E/AndroidRuntime(13459): at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
E/AndroidRuntime(13459): at android.graphics.Bitmap.nativeCreate(Native Method)
E/AndroidRuntime(13459): at android.graphics.Bitmap.createBitmap(Bitmap.java:942)
E/AndroidRuntime(13459): at android.graphics.Bitmap.createBitmap(Bitmap.java:913)
E/AndroidRuntime(13459): at android.graphics.Bitmap.createBitmap(Bitmap.java:880)
E/AndroidRuntime(13459): at com.horcrux.svg.RNSVGSvgViewShadowNode.drawOutput(RNSVGSvgViewShadowNode.java:45)
E/AndroidRuntime(13459): at com.horcrux.svg.RNSVGSvgViewShadowNode.onCollectExtraUpdates(RNSVGSvgViewShadowNode.java:41)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.ReactShadowNode.dispatchUpdates(ReactShadowNode.java:200)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:769)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:759)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:759)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:759)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:759)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:759)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:759)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:759)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:759)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:759)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:759)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.applyUpdatesRecursive(UIImplementation.java:759)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.updateViewHierarchy(UIImplementation.java:517)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIImplementation.dispatchViewUpdates(UIImplementation.java:505)
E/AndroidRuntime(13459): at com.facebook.react.uimanager.UIManagerModule.onBatchComplete(UIManagerModule.java:480)
E/AndroidRuntime(13459): at com.facebook.react.cxxbridge.NativeModuleRegistry.onBatchComplete(NativeModuleRegistry.java:99)
E/AndroidRuntime(13459): at com.facebook.react.cxxbridge.CatalystInstanceImpl$BridgeCallback.onBatchComplete(CatalystInstanceImpl.java:129)
E/AndroidRuntime(13459): at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
E/AndroidRuntime(13459): at android.os.Handler.handleCallback(Handler.java:739)
E/AndroidRuntime(13459): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(13459): at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
E/AndroidRuntime(13459): at android.os.Looper.loop(Looper.java:145)
E/AndroidRuntime(13459): at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
E/AndroidRuntime(13459): at java.lang.Thread.run(Thread.java:818)
W/ActivityManager( 2351):   Force finishing activity 1 com.MyApp/.MainActivity
D/InputDispatcher( 2351): Focused application set to: xxxx
D/InputDispatcher( 2351): Focus left window: 13459
D/PointerIcon( 2351): setMouseIconStyle1 pointerType: 1001 iconType:101 flag:0 pid:2351 uid:1000
D/PointerIcon( 2351): setMouseCustomIcon IconType is same.101
D/PointerIcon( 2351): setHoveringSpenIconStyle1 pointerType: 10001 iconType:1 flag:0 pid:2351 uid:1000
D/PointerIcon( 2351): setHoveringSpenCustomIcon IconType is same.1

For me adding: android:largeHeap=“true” in the application in the AndroidManifest resolve the issue.

    <application
      android:name=".MainApplication"
      android:allowBackup="true"
      android:label="MyLabel"
      android:icon="@mipmap/ic_launcher"
      android:largeHeap="true"
      android:theme="@style/AppTheme">

We might have found the cause for this crash, see PR #11804. Can you check whether the proposed fix solves this crash?

Anyone have an idea for a workaround? Since there seems to be some kind of memory leak, is there a way we can manually call some kind of garbage collection? I need my app to be able to run all day, while it always crashes at best about every ~12 hours.

This issue still exists in v0.24.1

I’ve just confirmed that this issue still exists in v0.23.1

Why is this closed while still happening? I’m on 0.47.2. None of proposed fixes works.

Same problem here with RN 0.38.0 on Android 5. A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0xcbd400a4 in tid 15158 (mqt_js) I can reproduce it with animatedcrash app made by @iggyfisk (thanks!) when JS Dev Mode is on. I can not reproduce it on my app and animatedcrash app when JS Dev Mode is off. I don’t use ART directly in my app. (Not sure the libraries use it.) Probably, it’s Animated’s problem.