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.66k stars 2.21k forks source link

🔥App is open for too long firebase stops working after few hours. #2647

Closed Nidhi-Gandhi closed 4 years ago

Nidhi-Gandhi commented 5 years ago

Issue

Describe your issue here

If app is open for long time then after few hours firebase stops working. I am working with react-native and react-native-firebase on chat application. If I leave chat screen open overnight then in morning it stops working. Once I closed and reopened it then it working fine.

For Example: I sent my last message "Good night" and I slept but my chat screen was open. When I wakeup in morning at that time app was open and I could see my chat screen. I tried to sent message in chat to wish 'Good Morning' but it was stops working, nothing happened. When I closed the app and reopened it then it was works fine. I also received some other messages that arrived in morning.

It seems like firebase looses connectivity after few hours. Not any firebase queries are executes. I use Phone authentication for sign up. Android release SHA-1 key was already added in firebase.

    "react-native-firebase": "^4.3.8",
    "react-native-gifted-chat": "^0.7.3",
    "react-native": "0.55.4",

Project Files

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # N/A # Uncomment the next line to define a global platform for your project # platform :ios, '9.0' target 'picurbrain' do # Uncomment the next line if you're using Swift or would like to use dynamic frameworks # use_frameworks! # Pods for RNFirebaseStarter # Required by RNFirebase pod 'Firebase/Core', '~> 5.3.0' # [OPTIONAL PODS] - comment out pods for firebase products you won't be using. # pod 'Firebase/AdMob', '~> 5.3.0' pod 'Firebase/Auth', '~> 5.3.0' pod 'Firebase/Crash', '~> 5.3.0' pod 'Firebase/Database', '~> 5.3.0' pod 'Firebase/Functions', '~> 5.3.0' pod 'Firebase/DynamicLinks', '~> 5.3.0' pod 'Firebase/Firestore', '~> 5.3.0' # pod 'Firebase/Invites', '~> 5.3.0' pod 'Firebase/Messaging', '~> 5.3.0' pod 'Firebase/RemoteConfig', '~> 5.3.0' pod 'Firebase/Storage', '~> 5.3.0' pod 'Firebase/Performance', '~> 5.3.0' pod 'Fabric', '~> 1.7.5' pod 'Crashlytics', '~> 3.10.4' end ``` #### `AppDelegate.m`: ```objc // N/A /** * Copyright (c) 2015-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #import "AppDelegate.h" #import #import #import #import "RNFirebaseNotifications.h" #import "RNFirebaseMessaging.h" #import "RNSplashScreen.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FIRApp configure]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if (![defaults boolForKey:@"notFirstRun"]) { [defaults setBool:YES forKey:@"notFirstRun"]; [defaults synchronize]; [[FIRAuth auth] signOut:NULL]; } [RNFirebaseNotifications configure]; NSURL *jsCodeLocation; jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"picurbrain" initialProperties:nil launchOptions:launchOptions]; rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; [RNSplashScreen show]; return YES; } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [[RNFirebaseNotifications instance] didReceiveLocalNotification:notification]; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{ [[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { [[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings]; } @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 // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() // <-- Check this line exists and is above jcenter jcenter() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:3.1.3' classpath 'com.google.gms:google-services:4.0.1' classpath 'com.google.firebase:firebase-plugins:1.1.1' classpath 'io.fabric.tools:gradle:1.25.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() mavenLocal() jcenter() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } maven { url 'https://maven.google.com' } maven { url "https://jitpack.io" } } } ``` #### `android/app/build.gradle`: ```groovy // N/A apply plugin: "com.android.application" apply plugin: "com.google.firebase.firebase-perf" apply plugin: 'io.fabric' import com.android.build.OutputFile /** * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets * and bundleReleaseJsAndAssets). * These basically call `react-native bundle` with the correct arguments during the Android build * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the * bundle directly from the development server. Below you can see all the possible configurations * and their defaults. If you decide to add a configuration block, make sure to add it before the * `apply from: "../../node_modules/react-native/react.gradle"` line. * * project.ext.react = [ * // the name of the generated asset file containing your JS bundle * bundleAssetName: "index.android.bundle", * * // the entry file for bundle generation * entryFile: "index.android.js", * * // whether to bundle JS and assets in debug mode * bundleInDebug: false, * * // whether to bundle JS and assets in release mode * bundleInRelease: true, * * // whether to bundle JS and assets in another build variant (if configured). * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants * // The configuration property can be in the following formats * // 'bundleIn${productFlavor}${buildType}' * // 'bundleIn${buildType}' * // bundleInFreeDebug: true, * // bundleInPaidRelease: true, * // bundleInBeta: true, * * // whether to disable dev mode in custom build variants (by default only disabled in release) * // for example: to disable dev mode in the staging build type (if configured) * devDisabledInStaging: true, * // The configuration property can be in the following formats * // 'devDisabledIn${productFlavor}${buildType}' * // 'devDisabledIn${buildType}' * * // the root of your project, i.e. where "package.json" lives * root: "../../", * * // where to put the JS bundle asset in debug mode * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", * * // where to put the JS bundle asset in release mode * jsBundleDirRelease: "$buildDir/intermediates/assets/release", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in debug mode * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in release mode * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", * * // by default the gradle tasks are skipped if none of the JS files or assets change; this means * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to * // date; if you have any other folders that you want to ignore for performance reasons (gradle * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ * // for example, you might want to remove it from here. * inputExcludes: ["android/**", "ios/**"], * * // override which node gets called and with what additional arguments * nodeExecutableAndArgs: ["node"], * * // supply additional arguments to the packager * extraPackagerArgs: [] * ] */ project.ext.react = [ entryFile: "index.js" ] apply from: "../../node_modules/react-native/react.gradle" /** * Set this to true to create two separate APKs instead of one: * - An APK that only works on ARM devices * - An APK that only works on x86 devices * The advantage is the size of the APK is reduced by about 4MB. * Upload all the APKs to the Play Store and people will download * the correct one based on the CPU architecture of their device. */ def enableSeparateBuildPerCPUArchitecture = false /** * Run Proguard to shrink the Java bytecode in release builds. */ def enableProguardInReleaseBuilds = false android { compileSdkVersion 27 buildToolsVersion "27.0.3" defaultConfig { applicationId "com.valltech.picurbrain" minSdkVersion 16 targetSdkVersion 27 versionCode 1 versionName "1.0" ndk { abiFilters "armeabi-v7a", "x86" } multiDexEnabled true vectorDrawables.useSupportLibrary = true } signingConfigs { release { if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) { storeFile file(MYAPP_RELEASE_STORE_FILE) storePassword MYAPP_RELEASE_STORE_PASSWORD keyAlias MYAPP_RELEASE_KEY_ALIAS keyPassword MYAPP_RELEASE_KEY_PASSWORD } } } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include "armeabi-v7a", "x86" } } buildTypes { release { minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" signingConfig signingConfigs.release } } // applicationVariants are e.g. debug, release applicationVariants.all { variant -> variant.outputs.each { output -> // For each separate APK per architecture, set a unique version code as described here: // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits def versionCodes = ["armeabi-v7a":1, "x86":2] def abi = output.getFilter(OutputFile.ABI) if (abi != null) { // null for the universal-debug, universal-release variants output.versionCodeOverride = versionCodes.get(abi) * 1048576 + defaultConfig.versionCode } } } } dependencies { implementation project(':react-native-gesture-handler') implementation project(':rn-fetch-blob') implementation project(':react-native-splash-screen') implementation project(':react-native-system-setting') implementation project(':react-native-image-crop-picker') implementation project(':react-native-document-picker') implementation project(':react-native-contacts') implementation(project(':react-native-firebase')) { transitive = false } implementation('com.crashlytics.sdk.android:crashlytics:2.9.3@aar') { transitive = true } implementation project(':react-native-vector-icons') implementation project(':react-native-image-picker') implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.android.support:appcompat-v7:27.1.1" implementation "com.facebook.react:react-native:+" // From node_modules implementation "com.google.android.gms:play-services-base:15.0.1" implementation "com.google.firebase:firebase-core:16.0.1" implementation "com.google.firebase:firebase-firestore:17.0.4" implementation "com.google.firebase:firebase-database:16.0.1" implementation "com.google.firebase:firebase-storage:16.0.1" implementation "com.google.firebase:firebase-crash:16.0.1" implementation "com.google.firebase:firebase-auth:16.0.2" implementation "com.google.firebase:firebase-messaging:17.1.0" implementation "com.google.firebase:firebase-perf:16.0.0" implementation "com.google.firebase:firebase-functions:16.1.0" } // Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' } apply plugin: 'com.google.gms.google-services' ``` #### `android/settings.gradle`: ```groovy // N/A rootProject.name = 'picurbrain' include ':react-native-fetch-blob' project(':react-native-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fetch-blob/android') include ':react-native-gesture-handler' project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android') include ':rn-fetch-blob' project(':rn-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/rn-fetch-blob/android') include ':react-native-splash-screen' project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android') include ':react-native-system-setting' project(':react-native-system-setting').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-system-setting/android') include ':react-native-image-crop-picker' project(':react-native-image-crop-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-crop-picker/android') include ':react-native-document-picker' project(':react-native-document-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-document-picker/android') include ':react-native-contacts' project(':react-native-contacts').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-contacts/android') include ':react-native-image-picker' project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android') include ':react-native-firebase' project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android') include ':react-native-vector-icons' project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android') include ':app' ``` #### `MainApplication.java`: ```java // N/A package com.valltech.picurbrain; import android.app.Application; import com.facebook.react.ReactApplication; import com.RNFetchBlob.RNFetchBlobPackage; import com.swmansion.gesturehandler.react.RNGestureHandlerPackage; import org.devio.rn.splashscreen.SplashScreenReactPackage; import com.ninty.system.setting.SystemSettingPackage; import com.reactnative.ivpusic.imagepicker.PickerPackage; import io.github.elyx0.reactnativedocumentpicker.DocumentPickerPackage; import com.rt2zz.reactnativecontacts.ReactNativeContacts; import com.imagepicker.ImagePickerPackage; import io.invertase.firebase.RNFirebasePackage; // optional packages - add/remove as appropriate import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage; import io.invertase.firebase.auth.RNFirebaseAuthPackage; import io.invertase.firebase.crash.RNFirebaseCrashPackage; import io.invertase.firebase.fabric.crashlytics.RNFirebaseCrashlyticsPackage; import io.invertase.firebase.firestore.RNFirebaseFirestorePackage; import io.invertase.firebase.functions.RNFirebaseFunctionsPackage; import io.invertase.firebase.messaging.RNFirebaseMessagingPackage; import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage; import io.invertase.firebase.perf.RNFirebasePerformancePackage; import io.invertase.firebase.storage.RNFirebaseStoragePackage; import io.invertase.firebase.database.RNFirebaseDatabasePackage; import com.oblador.vectoricons.VectorIconsPackage; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage; import com.facebook.soloader.SoLoader; import java.util.Arrays; import java.util.List; public class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } @Override protected List getPackages() { return Arrays.asList( new MainReactPackage(), new RNFetchBlobPackage(), new RNGestureHandlerPackage(), new SplashScreenReactPackage(), new SystemSettingPackage(), new PickerPackage(), new DocumentPickerPackage(), new ReactNativeContacts(), new ImagePickerPackage(), new RNFirebasePackage(), new RNFirebaseAnalyticsPackage(), new RNFirebaseAuthPackage(), new RNFirebaseCrashPackage(), new RNFirebaseCrashlyticsPackage(), new RNFirebaseFirestorePackage(), new RNFirebaseFunctionsPackage(), new RNFirebaseMessagingPackage(), new RNFirebaseNotificationsPackage(), new RNFirebasePerformancePackage(), new RNFirebaseStoragePackage(), new RNFirebaseDatabasePackage(), new VectorIconsPackage() ); } @Override protected String getJSMainModuleName() { return "index"; } }; @Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; } @Override public void onCreate() { super.onCreate(); SoLoader.init(this, /* native exopackage */ false); } } ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` Environment: OS: macOS 10.14.5 Node: 11.14.0 Yarn: 1.16.0 npm: 6.9.0 Watchman: 4.9.0 Xcode: Xcode 11.0 Build version 11A420a Android Studio: 3.5 AI-191.8026.42.35.5791312 Packages: (wanted => installed) react: 16.3.1 => 16.3.1 react-native: 0.55.4 => 0.55.4 ``` - **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:** - `e.g. 5.4.3` 4.3.8 - **`Firebase` module(s) you're using that has the issue:** - `e.g. Instance ID` firestore - **Are you using `TypeScript`?** - `Y/N` 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]

mikehardy commented 5 years ago

I wouldn't begin to troubleshoot on old versions. I see you put some modern versions in the top there, but the react-native info output shows react-native 0.55.4? Even if the versions you put at the top are correct your Podfile indicates you are on iOS SDKs 5.3.0. They are on 6.9.0 now - I can't imagine the amount of bugs (possibly with network-connection-resuming implications) they have fixed in the meanwhile

So - what exact versions are you on, and if they are not current, can you get current?

Ehesp commented 5 years ago

I'd also bet there's a high probability this is intended on the native sdks to help reduce bandwidth to firebase by cutting connections after prolonged activity. There could be many factors at play also; e.g. did the Internet cut-out during the night?

Nidhi-Gandhi commented 5 years ago

@mikehardy I am using react-native version 0.55.4. I update version in issue description too.

Nidhi-Gandhi commented 5 years ago

@Ehesp I am not sure but I was put Wi-Fi turned on whole night. So my mobile was connected through internet whole night. But I am not sure about internet cut-out. I will test it again and let you know more about this.

Ehesp commented 5 years ago

Thanks, it'd also be interesting to look into native logs and see whether anything is being caught.

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.