react-native-mmkv-storage: [Bug] EXC_BREAKPOINT crash after installLibrary on iOS 12.* devices

Describe the bug

Hey!

We see quite a lot of EXC_BREAKPOINT crashes in Production, mostly coming from old iOS devices (the problem is almost unique to iPhone 6, 6 Plus and 7, according to the bug-reporting tool). And it only happens on iOS 12.*. Works totally fine on any other type of device / OS.

Stacktrace below:

Exception Type:     EXC_BREAKPOINT 


EXC_BREAKPOINT: 

0  AppName facebook::jsi::WithRuntimeDecorator<facebook::react::(anonymous namespace)::ReentrancyCheck, facebook::jsi::Runtime, facebook::jsi::Runtime>::Around::Around(facebook::react::(anonymous namespace)::ReentrancyCheck&) (HermesExecutorFactory.cpp:123:7)
1  AppName facebook::jsi::WithRuntimeDecorator<facebook::react::(anonymous namespace)::ReentrancyCheck, facebook::jsi::Runtime, facebook::jsi::Runtime>::createPropNameIDFromAscii(char const*, unsigned long) (decorator.h:529:12)
2  AppName install(facebook::jsi::Runtime&) (jsi.h:365:20)
3  AppName -[MMKVNative installLibrary] (MMKVNative.mm:77:5)
4  libdispatch.dylib      __dispatch_client_callout
5  libdispatch.dylib      __dispatch_continuation_pop$VARIANT$mp
6  libdispatch.dylib      __dispatch_source_invoke$VARIANT$mp
7  libdispatch.dylib      __dispatch_main_queue_callback_4CF$VARIANT$mp
8  CoreFoundation         ___CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
9  CoreFoundation         ___CFRunLoopRun
10 CoreFoundation         _CFRunLoopRunSpecific
11 Foundation             -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
12 Foundation             -[NSRunLoop(NSRunLoop) runUntilDate:]

To Reproduce Steps to reproduce the behavior:

  1. Crash happens on application start with the library installed.

Platform Information:

  • OS: iOS, 12.*
  • React Native Version 0.64.*
  • Library Version 0.5.6

Additional context

We’re also using reanimated2, which is another JSI-library and doesn’t have the same problem. Which makes me think that something might be wrong during installLibrary process.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

Released v0.6.11

@abejfehr try the new fix in #195

@abejfehr I am working on a possible fix. Will update soon in #195

This started happening for me after upgrading react-native to 0.66

@haikov did the patch work?

Also happens on iOS 15.2.0 in production build. MMKV version : 0.6.6

Here is the stacktrace:

Crashed: com.apple.main-thread
0  pierre                         0x2e4378 facebook::jsi::WithRuntimeDecorator<facebook::react::(anonymous namespace)::ReentrancyCheck, facebook::jsi::Runtime, facebook::jsi::Runtime>::Around::Around(facebook::react::(anonymous namespace)::ReentrancyCheck&) + 123 (HermesExecutorFactory.cpp:123)
1  pierre                         0x2e1cac facebook::jsi::WithRuntimeDecorator<facebook::react::(anonymous namespace)::ReentrancyCheck, facebook::jsi::Runtime, facebook::jsi::Runtime>::createPropNameIDFromAscii(char const*, unsigned long) + 170 (decorator.h:170)
2  pierre                         0x37098c install(facebook::jsi::Runtime&) + 1672 (functional:1672)
3  pierre                         0x370850 -[MMKVNative installLibrary] + 88 (MMKVNative.mm:88)
4  libdispatch.dylib              0x3bac _dispatch_client_callout + 20
5  libdispatch.dylib              0x7080 _dispatch_continuation_pop + 504
6  libdispatch.dylib              0x1a1a4 _dispatch_source_invoke + 1356
7  libdispatch.dylib              0x12000 _dispatch_main_queue_callback_4CF + 772
8  CoreFoundation                 0xc5f00 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
9  CoreFoundation                 0x838c0 __CFRunLoopRun + 2540
10 CoreFoundation                 0x82734 CFRunLoopRunSpecific + 600
11 HIToolbox                      0x32f68 RunCurrentEventLoopInMode + 292
12 HIToolbox                      0x32cdc ReceiveNextEventCommon + 552
13 HIToolbox                      0x32a9c _BlockUntilNextEventMatchingListInModeWithFilter + 72
14 AppKit                         0x41ce0 _DPSNextEvent + 844
15 AppKit                         0x40584 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1332
16 AppKit                         0x325a4 -[NSApplication run] + 596
17 AppKit                         0x3c78 NSApplicationMain + 1064
18 AppKit                         0x2da084 _NSApplicationMainWithInfoDictionary + 22
19 UIKitMacHelper                 0x49ac UINSApplicationMain + 1280
20 UIKitCore                      0x3b28 UIApplicationMain + 164
21 pierre                         0x4e6c main + 14 (main.m:14)
22 ???                            0x1077ad0f4 (Missing)

Well after some investigation, I think the error is caused because accessing the runtime from the wrong thread. However I don’t understand why it is happening only on a specific version of iOS and not other versions.

Because the error is happening inside the dispatch block, maybe we can remove it and see if that would help.

https://github.com/ammarahm-ed/react-native-mmkv-storage/blob/8bf0bc1992eb3f8c4ca696185a7873b34a6e056e/ios/MMKVNative.mm#L44

Fork the master branch and try removing the following code

   if (!cxxBridge.runtime) {
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.001 * NSEC_PER_SEC),
                       dispatch_get_main_queue(), ^{
            /**
             When refreshing the app while debugging, the setBridge
             method is called too soon. The runtime is not ready yet
             quite often. We need to install library as soon as runtime
             becomes available.
             */
            [self installLibrary];
        });
        return;
    }
    

replace it with following:

 if (!cxxBridge.runtime) { 
        return;
    }

Then use it instead of the released version on npm.

If you have any people who can test, that would be great otherwise the only option is to either download ios 12.5 on an iphone and downgrade or release to production again to see if the error goes away/some new error comes up