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.71k stars 2.22k forks source link

🔥Can't modify config objects after they are in use for FIRDatabaseReferences #2838

Closed kevinEsherick closed 4 years ago

kevinEsherick commented 5 years ago

Issue

I'm getting the error displayed in title sometimes after upgrading to v6. Getting it seemingly randomly, unable to intentionally reproduce. Below are screenshots of the error and callstack. They both appear to have some information that might be helpful.

IMG_5323 IMG_5325


Project Files

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # Uncomment the next line to define a global platform for your project platform :ios, '9.0' target 'App' do # Uncomment the next line if you're using Swift or would like to use dynamic frameworks # use_frameworks! # Pods for App pod 'React', :path => '../node_modules/react-native' pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga' pod 'RNFBApp', :path => '../node_modules/@react-native-firebase/app' pod 'RNFBAnalytics', :path => '../node_modules/@react-native-firebase/analytics' pod 'RNFBAuth', :path => '../node_modules/@react-native-firebase/auth' pod 'RNFBDatabase', :path => '../node_modules/@react-native-firebase/database' pod 'RNFBRemoteConfig', :path => '../node_modules/@react-native-firebase/remote-config' pod 'RNFBCrashlytics', :path => '../node_modules/@react-native-firebase/crashlytics' pod 'Fabric', '~> 1.9.0' pod 'Crashlytics', '~> 3.12.0' pod 'Folly', :podspec => "../node_modules/react-native/third-party-podspecs/Folly.podspec" target 'AppTests' do inherit! :search_paths # Pods for testing end post_install do |installer| installer.pods_project.targets.each do |target| if target.name == "React" target.remove_from_project end end end end ``` #### `AppDelegate.m`: ```objc #import "AppDelegate.h" #import #import #import #import @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FIRApp configure]; NSURL *jsCodeLocation; jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; UIView *backgroundView = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] firstObject]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"App" initialProperties:nil launchOptions:launchOptions]; rootView.backgroundColor = [UIColor clearColor]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = backgroundView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; [backgroundView addSubview:rootView]; rootView.frame = backgroundView.frame; return YES; } // Required to register for notifications - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings]; } // Required for the register event. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. You must call the completion handler after handling the remote notification. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } // Required for the registrationError event. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error]; } // Required for the localNotification event. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [RCTPushNotificationManager didReceiveLocalNotification:notification]; } @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:** ``` React Native Environment Info: System: OS: macOS High Sierra 10.13.6 CPU: (4) x64 Intel(R) Core(TM) i5-2435M CPU @ 2.40GHz Memory: 1002.86 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 8.7.0 - /usr/local/bin/node Yarn: 1.2.1 - /usr/local/bin/yarn npm: 5.5.1 - /usr/local/bin/npm SDKs: iOS SDK: Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1 IDEs: Android Studio: 3.4 AI-183.6156.11.34.5692245 Xcode: 10.1/10B61 - /usr/bin/xcodebuild npmPackages: react: 16.8.3 => 16.8.3 react-native: 0.59.3 => 0.59.3 npmGlobalPackages: create-react-native-app: 1.0.0 react-native-app-id-fixed: 0.2.1 react-native-cli: 2.0.1 ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [ ] Android - [x] **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:** - `6.0.3` - **`Firebase` module(s) you're using that has the issue:** - `Realtime Database, maybe RemoteConfig` - **Are you using `TypeScript`?** - `N`


Think react-native-firebase is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]

luskin commented 4 years ago

@mikehardy We are actually not sure what "config objects" are. Literally the ONLY database usage in our app is database().ref(':db_key').... - could help us understand where we should be looking?

mikehardy commented 4 years ago

I think the patch https://github.com/tappollo/booster/blob/6d4c5f9e27519bb2347f4d09e106170351b450b7/app/patches/%40react-native-firebase%2Bdatabase%2B6.7.1.patch linked above from @zhigang1992 might do the trick for you @luskin - should apply via patch-package

The problem seems related to this - there is already a "config lock" object, it just does not seem to be working:

https://github.com/invertase/react-native-firebase/blob/377f34247798216d7ce8fee23ea541c2a908bcb2/packages/database/ios/RNFBDatabase/RNFBDatabaseCommon.m#L67-L103

Since the failure is apparently a synchronization failure, switching it to the main thread as a workaround as the patch does is a viable solution

If anyone with a keen eye for iOS synchronization issues can see why the lock isn't working to protect against config object access, a PR would be most welcome

fabellonnoe commented 4 years ago

Any fix for this issue?

mikehardy commented 4 years ago

@fabellonnoe one workaround as mentioned, and a reasonable lead on a deep fix. How did it work with the workaround integrated in your project via patch-package?

mikehardy commented 4 years ago

Just a note for anyone paying attention - we would dearly love help looking at the objective-c that's doing the synchronization on the config lock object. There is no current efforts within Invertase to troubleshoot this, but there are lots of participants on this issue, hopefully someone from the community can find the root cause

stale[bot] commented 4 years 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 the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.