Skip to content

SIGSEGV crash in HybridFunction::toJSFunction on Android during cold start #1150

@tadeumaia

Description

@tadeumaia

SIGSEGV crash in HybridFunction::toJSFunction on Android during cold start

What happened?

We're experiencing intermittent SIGSEGV crashes on Android during app startup. The crash occurs in margelo::nitro::HybridFunction::toJSFunction when NitroModules.install() is called.

The crash is:

  • Intermittent: 6 occurrences across 6 different users from around 40 userbase deploy
  • Not reproducible: Cannot reproduce locally or in dev builds
  • Production only: Only seen in release builds
  • Cross-device: Affects various Samsung, Xiaomi devices across Android 12, 15, and 16

The stacktrace shows the crash originates inside libhermes.so after being called from HybridFunction::toJSFunction.

Reproducible Code

On app startup - crash happens during Nitro initialization before any user code runs. We use MMKV which triggers Nitro installation at module load time.

Relevant log output

Sentry Crash Report

Error: SIGSEGV: Segfault

Stacktrace:
    at <unknown> (<unknown>)
    at facebook::jni::detail::FunctionWrapper<T>::call (<unknown>)
    at facebook::jni::detail::MethodWrapper<T>::dispatch (<unknown>)
    at margelo::nitro::JNitroModules::install (<unknown>)
    at margelo::nitro::install (<unknown>)
    at margelo::nitro::install (<unknown>)
    at margelo::nitro::HybridObject::toObject (<unknown>)
    at margelo::nitro::HybridObjectPrototype::createPrototype (<unknown>)
    at margelo::nitro::HybridObjectPrototype::createPrototype (<unknown>)
    at margelo::nitro::HybridFunction::toJSFunction (<unknown>)

Full Native Stacktrace #1 (Android 16 - SM-S711B)

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 22520 >>> br.com.treinoai.www <<<

backtrace:
  #00  pc 0x00000000000c1b14  /data/app/.../split_config.arm64_v8a.apk!libhermes.so (BuildId: 3742cb807f54bf165f89bd93a20345afc069184d)
  #01  pc 0x00000000000b1148  /data/app/.../split_config.arm64_v8a.apk!libhermes.so (BuildId: 3742cb807f54bf165f89bd93a20345afc069184d)
  #02  pc 0x00000000000e8a64  /data/app/.../split_config.arm64_v8a.apk!libhermes.so (BuildId: 3742cb807f54bf165f89bd93a20345afc069184d)
  #03  pc 0x00000000000a37d4  /data/app/.../split_config.arm64_v8a.apk!libhermes.so (BuildId: 3742cb807f54bf165f89bd93a20345afc069184d)
  #04  pc 0x000000000009c33c  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::HybridFunction::toJSFunction(facebook::jsi::Runtime&) const+220) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #05  pc 0x000000000009bd10  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::HybridObjectPrototype::createPrototype(facebook::jsi::Runtime&, std::__ndk1::shared_ptr<margelo::nitro::Prototype> const&)+472) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #06  pc 0x000000000009bcc0  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::HybridObjectPrototype::createPrototype(facebook::jsi::Runtime&, std::__ndk1::shared_ptr<margelo::nitro::Prototype> const&)+392) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #07  pc 0x0000000000085e44  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::HybridObject::toObject(facebook::jsi::Runtime&)+436) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #08  pc 0x0000000000098ea0  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::install(facebook::jsi::Runtime&)+56) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #09  pc 0x0000000000098d8c  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::install(facebook::jsi::Runtime&, std::__ndk1::shared_ptr<margelo::nitro::Dispatcher>)+124) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #10  pc 0x00000000000d3450  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::JNitroModules::install(...)+288) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #11  pc 0x00000000000d4114  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (facebook::jni::detail::MethodWrapper<...>::dispatch(...)+84) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #12  pc 0x00000000000d4044  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (facebook::jni::detail::FunctionWrapper<...>::call(...)+84) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  ...
  #15  pc 0x0000000000320272  /data/app/.../base.apk (com.margelo.nitro.NitroModules.install+70)
  ...
  #20  pc 0x00000000003a3a9c  /data/app/.../split_config.arm64_v8a.apk!libreactnative.so (facebook::react::JavaTurboModule::invokeJavaMethod(...)+11592) (BuildId: daceecb3f8ffe4c2)
  #21  pc 0x0000000000178550  /data/app/.../split_config.arm64_v8a.apk!libappmodules.so (facebook::react::__hostFunction_NativeNitroModulesSpecJSI_install(...)+1998848) (BuildId: dee755c329a0b32e03aaf4ae126bae948445d587)

Full Native Stacktrace #2 (Android 15 - 25078RA3EL)

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 28821 >>> br.com.treinoai.www <<<

backtrace:
  #00  pc 0x00000000000c1b14  /data/app/.../split_config.arm64_v8a.apk!libhermes.so (BuildId: 3742cb807f54bf165f89bd93a20345afc069184d)
  #01  pc 0x00000000000b1148  /data/app/.../split_config.arm64_v8a.apk!libhermes.so (BuildId: 3742cb807f54bf165f89bd93a20345afc069184d)
  #02  pc 0x00000000000e8a64  /data/app/.../split_config.arm64_v8a.apk!libhermes.so (BuildId: 3742cb807f54bf165f89bd93a20345afc069184d)
  #03  pc 0x00000000000a37d4  /data/app/.../split_config.arm64_v8a.apk!libhermes.so (BuildId: 3742cb807f54bf165f89bd93a20345afc069184d)
  #04  pc 0x000000000009c33c  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::HybridFunction::toJSFunction(facebook::jsi::Runtime&) const+220) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #05  pc 0x000000000009bd10  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::HybridObjectPrototype::createPrototype(facebook::jsi::Runtime&, std::__ndk1::shared_ptr<margelo::nitro::Prototype> const&)+472) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #06  pc 0x000000000009bcc0  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::HybridObjectPrototype::createPrototype(facebook::jsi::Runtime&, std::__ndk1::shared_ptr<margelo::nitro::Prototype> const&)+392) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #07  pc 0x0000000000085e44  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::HybridObject::toObject(facebook::jsi::Runtime&)+436) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #08  pc 0x0000000000098ea0  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::install(facebook::jsi::Runtime&)+56) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #09  pc 0x0000000000098d8c  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::install(facebook::jsi::Runtime&, std::__ndk1::shared_ptr<margelo::nitro::Dispatcher>)+124) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #10  pc 0x00000000000d3450  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::JNitroModules::install(...)+288) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  ...
  #15  pc 0x0000000000320272  /data/app/.../base.apk (com.margelo.nitro.NitroModules.install+70)

Full Native Stacktrace #3 (Android 12 - SM-G973F)

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 18313 >>> br.com.treinoai.www <<<

backtrace:
  #00  pc 0x00000000000c1b14  /data/app/.../split_config.arm64_v8a.apk!libhermes.so (BuildId: 3742cb807f54bf165f89bd93a20345afc069184d)
  #01  pc 0x00000000000b1148  /data/app/.../split_config.arm64_v8a.apk!libhermes.so (BuildId: 3742cb807f54bf165f89bd93a20345afc069184d)
  #02  pc 0x00000000000e8a64  /data/app/.../split_config.arm64_v8a.apk!libhermes.so (BuildId: 3742cb807f54bf165f89bd93a20345afc069184d)
  #03  pc 0x00000000000a37d4  /data/app/.../split_config.arm64_v8a.apk!libhermes.so (BuildId: 3742cb807f54bf165f89bd93a20345afc069184d)
  #04  pc 0x000000000009c33c  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::HybridFunction::toJSFunction(facebook::jsi::Runtime&) const+220) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #05  pc 0x000000000009bd10  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::HybridObjectPrototype::createPrototype(facebook::jsi::Runtime&, std::__ndk1::shared_ptr<margelo::nitro::Prototype> const&)+472) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #06  pc 0x000000000009bcc0  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::HybridObjectPrototype::createPrototype(facebook::jsi::Runtime&, std::__ndk1::shared_ptr<margelo::nitro::Prototype> const&)+392) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #07  pc 0x0000000000085e44  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::HybridObject::toObject(facebook::jsi::Runtime&)+436) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #08  pc 0x0000000000098ea0  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::install(facebook::jsi::Runtime&)+56) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #09  pc 0x0000000000098d8c  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::install(facebook::jsi::Runtime&, std::__ndk1::shared_ptr<margelo::nitro::Dispatcher>)+124) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  #10  pc 0x00000000000d3450  /data/app/.../split_config.arm64_v8a.apk!libNitroModules.so (margelo::nitro::JNitroModules::install(...)+288) (BuildId: 4bdcea491039fca58990cd081865bf3055be0464)
  ...
  #15  pc 0x0000000000320272  /data/app/.../base.apk (com.margelo.nitro.NitroModules.install+70)

Device Information

Device Android Version Occurrences
SM-S711B (Galaxy S23 FE) Android 16 2
SM-G973F (Galaxy S10) Android 12 1
SM-S921B (Galaxy S24) Android 16 1
25078RA3EL (Xiaomi) Android 15 1
2311DRK48G (Xiaomi) Android 15 1

OS Distribution:

  • Android 16: 3 occurrences (50%)
  • Android 15: 2 occurrences (33%)
  • Android 12: 1 occurrence (17%)

Environment

  • react-native-nitro-modules: 0.32.1
  • react-native-mmkv: 4.1.1 (uses Nitro)
  • react-native: 0.81.5
  • expo: 54.0.31
  • hermes: enabled (bundled with RN 0.81.5)
  • Architecture: New Architecture enabled

Observations

  1. Crash originates in Hermes: The first 4 frames are inside libhermes.so before the crash bubbles up from HybridFunction::toJSFunction

  2. Identical BuildIds: All crashes share the same libNitroModules.so BuildId (4bdcea491039fca58990cd081865bf3055be0464) and libhermes.so BuildId (3742cb807f54bf165f89bd93a20345afc069184d)

  3. Low occurrence rate: 6 crashes across thousands of users suggests a race condition or device-specific issue rather than a fundamental bug

  4. Cold start only: Crashes happen during initial NitroModules.install(), not during runtime or hot reload

Can you reproduce this issue?

No, I cannot reproduce this in development or on physical test devices. The crash only occurs in production builds on specific user devices.

Checklist

  • I have searched existing issues and this is not a duplicate
  • I have read the documentation
  • I have provided all relevant environment information
  • I have included complete stack traces

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions