invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.7k stars 2.21k forks source link

[🐛] 🔥 Firestore crash on app open iOS #7692

Closed nbonatsakis closed 5 months ago

nbonatsakis commented 7 months ago

Issue

Describe your issue here

We are seeing a high level of crashes in a production React Native app (around 1% of all users). The stack traces are slightly different across all crashes, but they all end up resulting in an illegal argument exception being thrown when the settings object is copied (copyWithZone). Based on my reading of the code, it seems like the Firestore code is trying to access the Firestore Settings object and for some reason, in these cases it is nil.

We are using basic Firestore functionality (collections and bundles) that get initialized on app open.

Stack trace example:

Fatal Exception: FIRInvalidArgumentException
0  CoreFoundation                 0xec678 (Missing UUID 5a6c1f41bf7032f6a1d65b894dd21362)
1  libobjc.A.dylib                0x2bc80 objc_exception_throw
2  MyApp                    0xeed44 firebase::firestore::util::ObjcThrowHandler(firebase::firestore::util::ExceptionType, char const*, char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) + 625 (string_view.h:625)
3  MyApp                    0xee840 firebase::firestore::util::Throw(firebase::firestore::util::ExceptionType, char const*, char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) + 97 (exception.cc:97)
4  MyApp                    0x11ee94 void firebase::firestore::util::ThrowInvalidArgument<>(char const*) + 94 (exception.h:94)
5  MyApp                    0x12686c -[FIRFirestoreSettings setCacheSizeBytes:] + 123 (FIRFirestoreSettings.mm:123)
6  MyApp                    0x126770 -[FIRFirestoreSettings copyWithZone:] + 98 (FIRFirestoreSettings.mm:98)
7  MyApp                    0x1217c8 -[FIRFirestore settings] + 202 (FIRFirestore.mm:202)
8  MyApp                    0x829ed0 +[RNFBFirestoreCommon setFirestoreSettings:appName:] + 74 (RNFBFirestoreCommon.m:74)
9  MyApp                    0x829cf4 +[RNFBFirestoreCommon getFirestoreForApp:] + 45 (RNFBFirestoreCommon.m:45)
10 MyApp                    0x6214 -[RNFirestoreBundle loadBundle::::] + 28 (RNFirestoreBundle.m:28)
11 CoreFoundation                 0x31714 (Missing UUID 5a6c1f41bf7032f6a1d65b894dd21362)
12 CoreFoundation                 0x311ac (Missing UUID 5a6c1f41bf7032f6a1d65b894dd21362)
13 CoreFoundation                 0x30fd4 (Missing UUID 5a6c1f41bf7032f6a1d65b894dd21362)
14 MyApp                    0x90ddec -[RCTModuleMethod invokeWithBridge:module:arguments:] + 587 (RCTModuleMethod.mm:587)
15 MyApp                    0x90fe3c facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&, int, (anonymous namespace)::SchedulingContext) + 196 (RCTNativeModule.mm:196)
16 MyApp                    0x90fa8c invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) + 419 (Optional.h:419)
17 libdispatch.dylib              0x26a8 (Missing UUID c49a5fc2c87339139603004f5d0175e7)
18 libdispatch.dylib              0x4300 (Missing UUID c49a5fc2c87339139603004f5d0175e7)
19 libdispatch.dylib              0xb894 (Missing UUID c49a5fc2c87339139603004f5d0175e7)
20 libdispatch.dylib              0xc3c4 (Missing UUID c49a5fc2c87339139603004f5d0175e7)
21 libdispatch.dylib              0x17004 (Missing UUID c49a5fc2c87339139603004f5d0175e7)
22 libdispatch.dylib              0x16878 (Missing UUID c49a5fc2c87339139603004f5d0175e7)
23 libsystem_pthread.dylib        0x1964 (Missing UUID 8f9c865b29f5346badd5fde40e008c66)
24 libsystem_pthread.dylib        0x1a04 (Missing UUID 8f9c865b29f5346badd5fde40e008c66)

Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "@react-native-firebase/analytics": "^18.6.1", "@react-native-firebase/app": "^18.6.1", "@react-native-firebase/auth": "^18.6.1", "@react-native-firebase/crashlytics": "^18.6.1", "@react-native-firebase/dynamic-links": "^18.6.1", "@react-native-firebase/firestore": "^18.6.1", "@react-native-firebase/functions": "^18.6.1", "@react-native-firebase/installations": "^18.6.1", "@react-native-firebase/messaging": "^18.6.1", "@react-native-firebase/perf": "^18.6.1", "@react-native-firebase/remote-config": "^18.6.1", } ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby ######################################## # Start React Native Firebase setup ######################################## $RNFirebaseAsStaticFramework = true # Disable IDFA collection by Firebase $RNFirebaseAnalyticsWithoutAdIdSupport = true ######################################## # Finish React Native Firebase setup ######################################## ``` #### `AppDelegate.m`: ```objc /@implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Initialise Firebase [FIRApp configure]; // Firebase Dynamic links fix: // Currently, iOS requires a workaround to make method swizzling work. // https://github.com/invertase/react-native-firebase/issues/4548#issuecomment-1252028059 [RNFBDynamicLinksAppDelegateInterceptor sharedInstance]; // TODO: It may not be appropriate to use the same API Key as Firebase [GMSServices provideAPIKey:[[[FIRApp defaultApp] options] APIKey]]; self.moduleName = @"MyApp"; // You can add your custom initial props in the dictionary below. // They will be passed down to the ViewController used by React Native. self.initialProps = @{}; return [super application:application didFinishLaunchingWithOptions:launchOptions]; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [CodePush bundleURL]; #endif } /// This method controls whether the `concurrentRoot`feature of React18 is turned on or off. /// /// @see: https://reactjs.org/blog/2022/03/29/react-v18.html /// @note: This requires to be rendering on Fabric (i.e. on the New Architecture). /// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`. - (BOOL)concurrentRootEnabled { return true; } // react-native-bootsplash - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initProps:(NSDictionary *)initProps { UIView *rootView = [super createRootViewWithBridge:bridge moduleName:moduleName initProps:initProps]; [RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; return rootView; } @end ```


Android

Click To Expand

#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` info Fetching system and libraries information... System: OS: macOS 14.2.1 CPU: (12) arm64 Apple M2 Pro Memory: 191.09 MB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.19.0 - /opt/homebrew/opt/node@18/bin/node Yarn: Not Found npm: 10.2.3 - /opt/homebrew/opt/node@18/bin/npm Watchman: Not Found Managers: CocoaPods: 1.12.1 - /Users/nick/.rvm/gems/ruby-3.2.2/bin/pod SDKs: iOS SDK: Platforms: DriverKit 23.2, iOS 17.2, macOS 14.2, tvOS 17.2, visionOS 1.0, watchOS 10.2 Android SDK: Not Found IDEs: Android Studio: 2023.1 AI-231.9392.1.2311.11255304 Xcode: 15.2/15C500b - /usr/bin/xcodebuild Languages: Java: 11.0.21 - /opt/homebrew/opt/openjdk@11/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: ^0.71.14 => 0.71.14 react-native-macos: Not Found npmGlobalPackages: *react-native*: Not Found ``` - **Platform that you're experiencing the issue on**: - [ x] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `18.6.1` - **`Firebase` module(s) you're using that has the issue:** - `firestore` - **Are you using `TypeScript`?** - `Y 5.1.0`


rgomezp commented 7 months ago

Looks like a slightly different crash log, but you're describing exactly what I and others are seeing:

https://github.com/invertase/react-native-firebase/issues/7697 https://github.com/invertase/react-native-firebase/issues/7695

I hope this gets looked at soon.

mikehardy commented 7 months ago

@rgomezp this crash trace looks very different

@nbonatsakis what happens when you use the current version here? it includes a new native firebase-ios-sdk version and may contain a fix

github-actions[bot] commented 6 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.