facebook / hermes

A JavaScript engine optimized for running React Native.
https://hermesengine.dev/
MIT License
9.74k stars 625 forks source link

Hermes crashes app when built in Release mode #608

Closed Vannevelj closed 2 years ago

Vannevelj commented 2 years ago

Bug Description

I have an iPad-only React Native app. Initially I saw some "Signal 6" crashes in my CI environment when about 10% of the Detox tests failed. I left it for a little while and now I bumped the app to RN65 with Hermes enabled. This resulted in the app crashing 100% of the time in Release builds, although Debug builds work perfectly fine (all CI passes). I can also run Debug builds in an Xcode simulator.

I don't have much to go on since the Detox tests crash with a fairly short stacktrace:

Signal 6 was raised
(
    0   Detox                               0x000000010304ba15 +[NSThread(DetoxUtils) dtx_demangledCallStackSymbols] + 37
    1   Detox                               0x000000010304ee10 __DTXHandleCrash + 464
    2   Detox                               0x000000010304f555 __DTXHandleSignal + 59
    3   libsystem_platform.dylib            0x00007fff60335d7d _sigtramp + 29
    4   ???                                 0x0000000000000001 0x0 + 1
    5   libsystem_c.dylib                   0x00007fff200fbcb5 abort + 120
    6   libc++abi.dylib                     0x00007fff20254692 abort_message + 241
    7   libc++abi.dylib                     0x00007fff20245dfd demangling_unexpected_handler() + 0
    8   libobjc.A.dylib                     0x00007fff20179ace _objc_terminate() + 96
    9   Detox                               0x000000010304fa4f __dtx_terminate() + 157
    10  libc++abi.dylib                     0x00007fff20253aa7 std::__terminate(void (*)()) + 8
    11  libc++abi.dylib                     0x00007fff2025635a __cxa_rethrow + 99
    12  libobjc.A.dylib                     0x00007fff20194149 objc_exception_rethrow + 37
    13  CoreFoundation                      0x00007fff2038a2cd CFRunLoopRunSpecific + 861
    14  Replay                              0x000000010199a18d +[RCTCxxBridge runRunLoop] + 274
    15  DetoxSync                           0x000000010450b00e swz_runRunLoopThread + 291
    16  Foundation                          0x00007fff2085c8a9 __NSThread__start__ + 1068
    17  libsystem_pthread.dylib             0x00007fff603438fc _pthread_start + 224
    18  libsystem_pthread.dylib             0x00007fff6033f443 thread_start + 15
)

Running the app as a Release build on my physical device just crashes the app straight away - the splash screen doesn't even show. If I run the Release build in Xcode I can see the following stacktrace:

2021-10-04 14:46:14.905 [fatal][tid:com.facebook.react.JavaScript] Could not get BatchedBridge, make sure your bundle is packaged correctly
2021-10-04 14:46:14.910197+0100 Replay[30152:8115614] *** Terminating app due to uncaught exception 'RCTFatalException: Could not get BatchedBridge, make sure your bundle is packaged correctly', reason: 'Could not get BatchedBridge, make sure your bundle is packaged correctly'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff20422fba __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007fff20193ff5 objc_exception_throw + 48
    2   Replay                              0x00000001008aa835 RCTGetFatalHandler + 0
    3   Replay                              0x00000001008c304e -[RCTCxxBridge handleError:] + 512
    4   Replay                              0x00000001008c1355 __34-[RCTCxxBridge _initializeBridge:]_block_invoke + 65
    5   Replay                              0x00000001008d7fd8 _ZN8facebook5react16RCTMessageThread7tryFuncERKNSt3__18functionIFvvEEE + 44
    6   Replay                              0x00000001008d7df8 ___ZN8facebook5react16RCTMessageThread8runAsyncENSt3__18functionIFvvEEE_block_invoke + 33
    7   CoreFoundation                      0x00007fff20390c74 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    8   CoreFoundation                      0x00007fff20390070 __CFRunLoopDoBlocks + 437
    9   CoreFoundation                      0x00007fff2038a9e5 __CFRunLoopRun + 857
    10  CoreFoundation                      0x00007fff2038a1a7 CFRunLoopRunSpecific + 567
    11  Replay                              0x00000001008be88d +[RCTCxxBridge runRunLoop] + 274
    12  Foundation                          0x00007fff2085c8a9 __NSThread__start__ + 1068
    13  libsystem_pthread.dylib             0x00007fff603438fc _pthread_start + 224
    14  libsystem_pthread.dylib             0x00007fff6033f443 thread_start + 15
)
libc++abi: terminating with uncaught exception of type NSException

It fails on line 324 in RCTCxxBridge.mm:

image

Below is a list of our app's dependencies:

```js "dependencies": { "@apollo/client": "^3.3.15", "@dudigital/react-native-zoomable-view": "1.0.16", "@hudl/jarvis": "^3.0.1", "@react-navigation/material-top-tabs": "^5.1.3", "@reduxjs/toolkit": "^1.5.1", "react": "17.0.2", "react-native": "0.65.1", "react-native-detox-context": "^0.3.0", "react-native-draggable-flatlist": "^2.6.2", "react-native-popup-menu": "0.15.10", "react-native-settings-list": "^1.8.0", "react-native-splash-screen": "3.0.6", "react-native-startup-time": "^2.0.0", "react-native-tab-view": "2.15.0", "react-native-toast-message": "^1.4.9", "react-native-zeroconf": "^0.13.2", "react-navigation-props-mapper": "^2.0.0", "react-redux": "^7.2.4", "redux-persist": "~6.0.0", "redux-sentry-middleware": "^0.2.2", "redux-thunk": "^2.3.0", "semver": "^7.3.5" }, "devDependencies": { "@babel/core": "7.12.9", "@babel/runtime": "7.12.5", "@hudl/goldstone": "3.1.0", "@hudl/jarvis-cli": "^1.7.1", "@react-native-community/eslint-config": "^3.0.0", "@testing-library/react-native": "^7.2.0", "@types/express": "^4.17.8", "@types/jest": "25.2.1", "@types/node": "^14.14.6", "@types/react-native": "^0.65.1", "@types/react-native-zeroconf": "^0.12.0", "@types/react-test-renderer": "^17.0.1", "@types/redux-mock-store": "^1.0.2", "abortcontroller-polyfill": "^1.7.1", "apollo": "^2.32.8", "babel-jest": "^24.9.0", "babel-plugin-module-resolver": "^4.0.0", "cross-fetch": "^3.0.6", "dayjs": "^1.9.6", "detox": "18.22.0", "detox-recorder": "^1.0.151", "eslint": "^7.32.0", "eslint-config-hudl-react-native": "^0.2.0", "eslint-config-prettier": "^8.3.0", "express": "^4.17.1", "jest": "^24.9.0", "jest-circus": "^26.6.3", "jest-fetch-mock": "^3.0.3", "jest-junit": "^12.2.0", "jest-teamcity": "^1.9.0", "metro-react-native-babel-preset": "0.65.1", "react-native-cli": "^2.0.1", "react-native-codegen": "^0.0.7", "react-native-flipper": "^0.102.0", "react-test-renderer": "^17.0.2", "redux-flipper": "^2.0.0", "redux-mock-store": "^1.5.4", "replace-in-file": "^6.1.0", "typescript": "4.2.4" }, "resolutions": { "react-devtools-core": "4.13.2", "@babel/core": "7.12.*", "@babel/runtime": "7.12.*" }, ```

At this point I'm not really sure where to look. Is this helpful? What other information can I provide?

Hermes version: 0.8.1 React Native version (if any): 0.65.1 OS version (if any): Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): arm64, arm-v7

Steps To Reproduce

No repro steps as of now but I hope to narrow this down with some help.

The Expected Behavior

Enabling Hermes does not crash the app in Release mode.

Vannevelj commented 2 years ago

Of course, right after I created this issue I might have found a solution..

Bumping react-native-reanimated from v2.1.0 to v2.2.2 seems to be doing the trick. Detox tests are currently running but they're actually passing whereas previously they wouldn't start at all.

gaberogan commented 2 years ago
Screen Shot 2021-11-01 at 4 23 38 PM

I'm on reanimated 2.2.2 and still getting the issue above ^

This is not in release mode btw

The crash happens when i "Open Debugger"