Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reloading Via React Native Debug Menu Causes Crash when Realm is installed #1424

Closed
somebody32 opened this issue Nov 10, 2020 · 26 comments
Closed
Labels
bug-bash-jan22 Issues visited during Bug Bash Jan 2022 🏠 Reanimated 2

Comments

@somebody32
Copy link

Description

Looks like another incarnation of #1285
Was happening on my project when tried to add reanimated 2 (just plainly calling <Animated.View />). I've tracked it down to a possible conflict with another dependancy: realmjs.
Below are the steps to reproduce it from reanimated 2 playground

Screenshots

image

Steps To Reproduce

  1. checkout reanimated 2 playground
  2. upgrade react native to 0.63.3
  3. add realm: yarn add realm
  4. npx pod-install
  5. run in simulator and try to refresh with cmd+R

Package versions

  • React: 16.13.1
  • React Native: 0.63.3
  • React Native Reanimated: 2.0.0-alpha.8
  • NodeJS: v14.9.0
@somebody32
Copy link
Author

@ReyhanFabianto but I'm not using Hermes (on ios this will be possible only with the next RN release)

@xKRUTOIx
Copy link

The same problem happens with me(I use realmjs as well)

@mattijsf
Copy link

mattijsf commented Mar 7, 2021

We're in the process of removing realm-js, mainly due to lack of Hermes support and this is another...

These lines are causing the crash:

JSCRuntime::~JSCRuntime() {
  // On shutting down and cleaning up: when JSC is actually torn down,
  // it calls JSC::Heap::lastChanceToFinalize internally which
  // finalizes anything left over.  But at this point,
  // JSValueUnprotect() can no longer be called.  We use an
  // atomic<bool> to avoid unsafe unprotects happening after shutdown
  // has started.
  ctxInvalid_ = true;
  JSGlobalContextRelease(ctx_);
#ifndef NDEBUG
  assert(
      objectCounter_ == 0 && "JSCRuntime destroyed with a dangling API object");
  assert(
      stringCounter_ == 0 && "JSCRuntime destroyed with a dangling API string");
#endif
}

I guess both modules are tinkering somewhat with JSI and are causing this problem.

I've added the following lines to Podfile to prevent the app from crashing upon reload (in our case temporarily). Should be used with care though! As obviously something is going wrong on either Realm or Reanimated v2's side and this error hints towards a memory issue/leak. The NDEBUG flag within the Realm-jsi module is only used for reference counting.

installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        if target.name == "React-jsi"
          puts "*** Patching React-jsi pod..."
          puts "***"
          puts "*** - Adding NDEBUG=1 to silence the 'JSCRuntime destroyed with a dangling API object' crash upon reload"
          puts "***"
          puts "*** This is cause by realm-js and reanimated v2 being loaded both at runtime."
          puts "*** It's recommended to remove realmjs as it is also incompatible with Hermes."
          puts "*** After which this workaround can be removed from Podfile."
          puts "*** Done"
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'NDEBUG=1'
        end
      end
    end

@somebody32
Copy link
Author

@mattijsf great workaround, will try it, thanks!

just curious though, to what are you migrating away from realm?

@mattijsf
Copy link

mattijsf commented Mar 7, 2021

@mattijsf great workaround, will try it, thanks!

just curious though, to what are you migrating away from realm?

The workaround is not that great though. It mostly suppresses the fact that there is a memory leak I'm afraid. But in day-to-day development where a full reload happens often it makes life a bit more enjoyable...

We migrated to sqlite for the reason it's proven stable and well maintained. Come to think of it... could be a nice next project of software-mansion to wrap their head around! A lean db solution with a proper API (realm comes close to this)... 👍

@davx1992
Copy link

Having same issue, and have Realm in project as well.

@YaoHuiJi
Copy link

YaoHuiJi commented Apr 3, 2021

exactly the same issue here, I have realm-js in my project, everything works well until I upgrade Reanimated from v1 to v2.1.0

@enigmablue
Copy link

Have the same problem, is there any workaround or planned fix for this? Thanks.

@whalemare
Copy link

Any comments from devs?

@Reactplus-Ngoc
Copy link

same issue with realm , ios

@buzunboy
Copy link

same issue, realm and ios project.

@kraenhansen
Copy link

We've released a new version of Realm JS with support for the Hermes engine: Realm JS v10.20.0-alpha.2.

Please take it for a spin and provide any feedback or issues you might have using the Hermes issue template over at the Realm JS repository. Thanks for your patience!

@LouisIV
Copy link

LouisIV commented Dec 4, 2021

@kraenhansen can we expect this to work for ios? Your release notes only mention Android. Is the iOS side something you're working on?

Tried out the alpha version. Seems to work on iOS.

@kraenhansen
Copy link

can we expect this to work for ios?

Yep, iOS and Android are both supported.
See this issue for the current state of our Hermes support.

@arinjay
Copy link

arinjay commented Jan 12, 2022

The same crash is happening without realm installed in the project.

"react-native-reanimated": "2.3.1", (in package.json)

podfile

platform :ios, '12.1'
use_frameworks!:linkage => :static


target 'xx' do
  
   config = use_native_modules!
   
  pod 'SSZipArchive'
  pod 'lottie-ios'
  pod 'FBSDKShareKit',                    '~> 8.2.0'
  
  #PaymentJuspaySDKs
  pod 'HyperSDK',                         '2.0.82'
  
  # PaymentCheckout SDKs
  pod 'CheckoutKit',                      '~> 3.0.4',      :build_type => :dynamic_framework
  
  pod 'Shimmer',                          '1.0.2'
  pod 'GoogleMaps',                       '4.2.0'
 
  use_react_native!(
      :path => config[:reactNativePath],
      # to enable hermes on iOS, change `false` to `true` and then install pods
      :hermes_enabled => false
    )
    end
end

@jakub-gonet
Copy link
Member

Seems like the problem with Realm was resolved. I'll close this issue. Please let me know if that's not the case.

@arinjay Please open a new issue since it's not directly related to Realm being installed. In addition to things you provided please post full crash info as well and repro example if possible. Thanks!

@jakub-gonet jakub-gonet added the bug-bash-jan22 Issues visited during Bug Bash Jan 2022 label Jan 28, 2022
trackwell-mike added a commit to trkwll/react-native-queue that referenced this issue Apr 13, 2022
@mayckondf
Copy link

This bug is still open :/ I just had the issue with the version 10.21.1, if someone knows how to fix without the workaround of @mattijsf please let me know, and thanks mattjsf

@devsales
Copy link

Same here... I came across the issue while trying to use react-native-draggable-flatlist. I posted an issue there and someone suggested to upgrade realm to the rc version, which currently should be 11.0.0-rc.2. I gave it a try but that didn't help unfortunately :( the app didn't even start after the update...

@jakub-gonet can you please reopen this issue?

@hanselsen
Copy link

@jakub-gonet this is still an issue on 2.12.0

@JB-CHAUVIN
Copy link

Still the issue in RE3 3.0.2 :

Assertion failed: (objectCounter_ == 0 && "JSCRuntime destroyed with a dangling API object"), function ~JSCRuntime, file JSCRuntime.cpp, line 395.
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot DYLD_LIBRARY_PATH=/Users/cegedim/Library/Developer/Xcode/DerivedData/Docavenue-cmzwsspleglbdpbefyrrtudtsnhq/Build/Products/Debug-iphonesimulator:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMTLCapture.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib DYLD_FRAMEWORK_PATH=/Users/cegedim/Library/Developer/Xcode/DerivedData/Docavenue-cmzwsspleglbdpbefyrrtudtsnhq/Build/Products/Debug-iphonesimulator
Assertion failed: (objectCounter_ == 0 && "JSCRuntime destroyed with a dangling API object"), function ~JSCRuntime, file JSCRuntime.cpp, line 395.
CoreSimulator 857.13 - Device: iPhone 1

@joshsambrook
Copy link

I'm still getting this issue with version @3.1.0 and react native @0.71.7. Anyone know of a solid fix?

@altaywtf
Copy link

altaywtf commented May 24, 2023

having the same issue on Android TV emulator with

  • react-native-tvos@0.69.8-0
  • react-native-reanimated@3.1.0
  • react-native-screens@3.20.0 (if relevant)

I don't even have Realm installed 🤔

whenever I reload the app via debug menu (or R), it crashes consistenly:

/Users/dlowder/iosProjects/react-native-tvos/ReactCommon/jsi/JSCRuntime.cpp:402: virtual facebook::jsc::JSCRuntime::~JSCRuntime(): assertion "objectCounter_ == 0 && "JSCRuntime destroyed with a dangling API object"" failed
Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 6628 (mqt_js), pid 6575
Stack trace
Thread 0 Crashed:
0   libc.so                         0x7ca099a894        abort
1   libc.so                         0x7ca099ac60        __assert2
2   libjscexecutor.so               0x796929dc50        facebook::jsc::JSCRuntime::~JSCRuntime
3   libjscexecutor.so               0x796929dca0        facebook::jsc::JSCRuntime::~JSCRuntime
4   libreanimated.so                0x792b03c6f0        <unknown> + 520412710640
5   libreanimated.so                0x792b03cdec        std::__ndk1::__shared_ptr_pointer<T>::__on_zero_shared
6   libreanimated.so                0x792afb51c4        <unknown> + 520412156356
7   libreanimated.so                0x792afb5138        <unknown> + 520412156216
8   libreanimated.so                0x792afd34d4        std::__ndk1::shared_ptr<T>::~shared_ptr
9   libreanimated.so                0x792afd51d0        <unknown> + 520412287440
10  libreanimated.so                0x792afd4f04        reanimated::NativeReanimatedModule::~NativeReanimatedModule
11  libreanimated.so                0x792b0d4078        std::__ndk1::__shared_ptr_emplace<T>::__on_zero_shared
12  libjscexecutor.so               0x79692a1f78        <unknown> + 521455411064
13  libjsc.so                       0x796cbcd9a4        <unknown> + 521515358628
14  libjsc.so                       0x796cf83394        <unknown> + 521519248276
15  libjsc.so                       0x796cf80ae8        <unknown> + 521519237864
16  libjsc.so                       0x796cf80994        <unknown> + 521519237524
17  libjsc.so                       0x796cd20b64        <unknown> + 521516747620
18  libjsc.so                       0x796cd08e3c        <unknown> + 521516650044
19  libjsc.so                       0x796cd22360        <unknown> + 521516753760
20  libjsc.so                       0x796cd0da30        <unknown> + 521516669488
21  libjsc.so                       0x796d0a0d80        <unknown> + 521520418176
22  libjsc.so                       0x796cfc5858        <unknown> + 521519519832
23  libjsc.so                       0x796cbd7d90        JSGlobalContextRelease
24  libjscexecutor.so               0x796929dbf8        facebook::jsc::JSCRuntime::~JSCRuntime
25  libjscexecutor.so               0x796929dca0        facebook::jsc::JSCRuntime::~JSCRuntime
26  libjscexecutor.so               0x796928a0d8        <unknown> + 521455313112
27  libjscexecutor.so               0x7969289e04        <unknown> + 521455312388
28  libjscexecutor.so               0x7969297f0c        facebook::react::JSIExecutor::~JSIExecutor
29  libjscexecutor.so               0x7969297f3c        facebook::react::JSIExecutor::~JSIExecutor
30  libreactnativejni.so            0x79667101f4        <unknown> + 521409724916
31  libreactnativejni.so            0x7966710160        <unknown> + 521409724768
32  libreactnativejni.so            0x796671f4fc        <unknown> + 521409787132
33  libreactnativejni.so            0x796671f4c4        <unknown> + 521409787076
34  libreactnativejni.so            0x796671f434        <unknown> + 521409786932
35  libreactnativejni.so            0x796671f3e8        <unknown> + 521409786856
36  libreactnativejni.so            0x796671f3c0        <unknown> + 521409786816
37  libreactnativejni.so            0x796671e104        <unknown> + 521409782020
38  libreactnativejni.so            0x796663cee4        <unknown> + 521408859876
39  libreactnativejni.so            0x796663ce90        std::__ndk1::function<T>::operator()
40  libreactnativejni.so            0x796667e2c0        <unknown> + 521409127104
41  libreactnativejni.so            0x796667e25c        <unknown> + 521409127004
42  libreactnativejni.so            0x796667e210        <unknown> + 521409126928
43  libreactnativejni.so            0x796667e1e8        <unknown> + 521409126888
44  libreactnativejni.so            0x796667d12c        <unknown> + 521409122604
45  libreactnativejni.so            0x796663cee4        <unknown> + 521408859876
46  libreactnativejni.so            0x796663ce90        std::__ndk1::function<T>::operator()
47  libreactnativejni.so            0x7966677e88        <unknown> + 521409101448
48  libreactnativejni.so            0x7966677de4        <unknown> + 521409101284
49  libreactnativejni.so            0x7966677d98        <unknown> + 521409101208
50  libreactnativejni.so            0x7966677d70        <unknown> + 521409101168
51  libreactnativejni.so            0x7966676a78        <unknown> + 521409096312
52  libreactnativejni.so            0x796663cee4        <unknown> + 521408859876
53  libreactnativejni.so            0x796663ce90        std::__ndk1::function<T>::operator()
54  libreactnativejni.so            0x796663cc8c        facebook::react::JNativeRunnable::run
55  libreactnativejni.so            0x796663ce44        facebook::jni::detail::MethodWrapper<T>::dispatch
56  libreactnativejni.so            0x796663d064        facebook::jni::detail::CallWithJniConversions<T>::call
57  libreactnativejni.so            0x796663ccd4        facebook::jni::detail::FunctionWrapper<T>::call
58  libreactnativejni.so            0x796663c948        facebook::jni::detail::MethodWrapper<T>::call
59  libart.so                       0x79ee440754        <unknown> + 523688478548
60  <unknown>                       0x9b2819b0          <unknown>

works fine on Apple TV emulator.

@ShepSims
Copy link

ShepSims commented Jun 2, 2023

Seeing the same issue when having react-native-firebase/messaging onMessage running and calling RNRestart.restart()

The solution from @mattijsf sadly does not work here

@meedwire
Copy link

doesn't seem to happen in version 2.3

@maydersonmellops
Copy link

Same here 1464

@csasiyash
Copy link

@altaywtf Any update on this issue? I am also stuck with this error on every reload of application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-bash-jan22 Issues visited during Bug Bash Jan 2022 🏠 Reanimated 2
Projects
None yet
Development

No branches or pull requests