Closed johanblumenberg closed 11 months ago
:warning: | Newer Version of React Native is Available! |
---|---|
:information_source: | You are on a supported minor version, but it looks like there's a newer patch available. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases. |
The calling code is located in react-native-vision-camera
Have you reporeted this also to react-native-vision-camera
issue tracker (cc @mrousavy)?
The calling code is located in react-native-vision-camera
Have you reporeted this also to
react-native-vision-camera
issue tracker (cc @mrousavy)?
No, since the crash is caused by code in react-native
I did not report any bug to react-native-vision-camera
. Is there any problem with how react-native-vision-camera
uses react-native
?
No, since the crash is caused by code in react-native I did not report any bug to react-native-vision-camera. Is there any problem with how react-native-vision-camera uses react-native?
I'm unsure but crashes that happens on specific libraries, should be reported to library authors. They have a better understanding on how the library interacts with the core of React Native and can point back to us, if the issue is inside the core.
@cortinico I'm quite sure that the code that I pointed to in react-native
will crash now and then for any library that calls getJSCallInvokerHolder()
, because the code that constructs the singleton is obviously not thread safe.
Some more details about this bug:
The method com.mrousavy.camera.frameprocessor.FrameProcessorRuntimeManager()
is calling getJSCallInvokerHolder()
on thread pool-2-thread-1
:
https://github.com/mrousavy/react-native-vision-camera/blob/06cbb742fbab331bfec3f6fce83d4751fb8dc2bc/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt#L66
The method com.swmansion.reanimated.NativeProxy()
calling getJSCallInvokerHolder()
on thread mqt_js
:
https://github.com/software-mansion/react-native-reanimated/blob/7029f160220d37164c6da15ba943cc6bb48252e6/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java#L25
Since these two invocations are both done at app start and on different threads, there is nothing that prevents the race condition in getJSCallInvokerHolder()
, and this will crash every now and then. The same thing will happen for any app or library that calls getJSCallInvokerHolder()
, if the app contains multiple libraries that try to call getJSCallInvokerHolder()
.
Suggestion for how to solve the bug:
diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java
index 0329ae8e92b..4c1539f0c99 100644
--- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java
+++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java
@@ -109,7 +109,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
private static native HybridData initHybrid();
- public native CallInvokerHolderImpl getJSCallInvokerHolder();
+ public synchronized native CallInvokerHolderImpl getJSCallInvokerHolder();
public native CallInvokerHolderImpl getNativeCallInvokerHolder();
Other alternatives:
This issue was closed because it has been stalled for 7 days with no activity.
quality is hard
seven days means problem solved
open source today
So sad :'(
Description
We see this crash now and then:
I interpet this message as there is a stale global object reference that was used. Perhaps it has been deallocated.
This is the interesting parts of the stack trace:
FrameProcessorRuntimeManager
constructor callsgetJSCallInvokerHolder()
which is a native method onCatalystInstanceImpl
.JniMethodEndWithReferenceHandleResult()
indicates that this method is trying to return a reference to an object. There is something wrong with this object to be returned, and the JVM callsabort()
.This is the
getJSCallInvokerHolder()
method: https://github.com/facebook/react-native/blob/bcec590071202608ee2e87feb02791e292457d94/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp#L374jsCallInvokerHolder_
is a smart pointer holding a reference to what looks to be a singleton. If two threads call this method at the same time, there is a race and possibly a crash. Both threads will find that the reference is null, and both threads will go on and create an object. Then both threads will assign the globaljsCallInvokerHolder_
reference, the later will override the first. The first object will be deallocated, but the first thread will continue and try to return the deallocated object to the caller.The calling code is located in
react-native-vision-camera
: https://github.com/mrousavy/react-native-vision-camera/blob/06cbb742fbab331bfec3f6fce83d4751fb8dc2bc/android/src/main/java/com/mrousavy/camera/CameraViewModule.kt#L66It executes some initialization code on a thread pool, that calls
CatalystInstanceImpl.getJSCallInvokerHolder()
.React Native Version
0.70.6
Output of
npx react-native info
info Fetching system and libraries information... System: OS: macOS 13.2.1 CPU: (8) arm64 Apple M1 Memory: 58.53 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node Yarn: 1.22.19 - ~/.yvm/shim/yarn npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm Watchman: Not Found Managers: CocoaPods: Not Found SDKs: iOS SDK: Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1 Android SDK: API Levels: 30, 31, 33 Build Tools: 30.0.2, 30.0.3, 31.0.0 System Images: android-30 | Google Play ARM 64 v8a, android-33 | Google Play ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: Not Found Xcode: 14.2/14C18 - /usr/bin/xcodebuild Languages: Java: 17.0.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: Not Found react-native: Not Found react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Steps to reproduce
N/A
Snack, code example, screenshot, or link to a repository
N/A