Skip to content

PromisImpl java class is not thread safe #35068

@atkaygro

Description

@atkaygro

Description

As obvious by inspection the PromiseImpl java class (https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java) is not thread safe as it takes zero precautions in that direction.
And as expected I get stacktraces for the android version of an app i work on, which have the reject method of that class at the top. Here is an example:
Exception java.lang.NullPointerException: Attempt to invoke interface method 'void com.facebook.react.bridge.Callback.invoke(java.lang.Object[])' on a null object reference at com.facebook.react.bridge.PromiseImpl.reject (PromiseImpl.java:231) at com.facebook.react.bridge.PromiseImpl.reject (PromiseImpl.java:70) at com.reactnativesystemnavigationbar.SystemNavigationBarModule.lambda$setSystemUIFlags$3$SystemNavigationBarModule (SystemNavigationBarModule.java:253) at com.reactnativesystemnavigationbar.-$$Lambda$SystemNavigationBarModule$vlfAsxgRC5ib2FXGmoNuZpOBPaY.run at android.os.Handler.handleCallback (Handler.java:907) at android.os.Handler.dispatchMessage (Handler.java:105) at android.os.Looper.loop (Looper.java:216) at android.app.ActivityThread.main (ActivityThread.java:7625) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:987)
The line 231 in question:
mReject.invoke(errorInfo);
fails because the mReject member is null.
I noticed this on react-native 0.64.3, but alas the newest version is not thread safe as well.
Note: This can cause other subtle and nonreproducible malfunctions for android apps, since this is a fairly basic functionality.

Version

0.64.3-0.70

Output of npx react-native info

System:
OS: macOS 12.6
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 1.26 GB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 16.9.1 - ~/.nvm/versions/node/v16.9.1/bin/node
Yarn: 1.22.10 - ~/.npm-global/bin/yarn
npm: 7.21.1 - ~/.nvm/versions/node/v16.9.1/bin/npm
Watchman: 2022.07.04.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /Users/kaygrossblotekamp/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
Android SDK:
API Levels: 23, 28, 29, 30, 31, 32
Build Tools: 23.0.1, 23.0.2, 23.0.3, 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0, 33.0.0
System Images: android-25 | Google APIs ARM 64 v8a, android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom, android-31 | Google Play Intel x86 Atom_64, android-32 | Google APIs Intel x86 Atom_64, android-32 | Google Play Intel x86 Atom_64, android-33 | Google APIs Intel x86 Atom_64
Android NDK: 23.0.7599858
IDEs:
Android Studio: 4.2 AI-202.7660.26.42.7351085
Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.8 - /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.1 => 17.0.1
react-native: facebook/react-native#0.64-stable => 0.64.3
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

  • Have an app with thousands of instalations live
  • Look at the stacktraces for the android version
  • Inspection of mentioned source file is recommended instead

Snack, code example, screenshot, or link to a repository

https://snack.expo.dev/mWlJ369TN

Note: Only reporduces in enough tries and on a diverse enough installation base.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Triage 🔍StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions