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.54k stars 2.19k forks source link

Production apps read empty cache data #1126

Closed KasparasGud closed 5 years ago

KasparasGud commented 6 years ago

Issue

The bug only occurs after installing the app from play store on some devices (mostly samsung). It seems as though firestore is reading cached data that is empty instead of requesting new data from the server. I can't reproduce the bug on DEV build and can't debug for this reason (No errors in logcat).

If you clear the data of the app in settings it starts to work again. But most of the users don't want to bother and just leave 1* reviews :/

In componentDidMount() i fetch all reports that are not older than 59 minutes.

this.unsubscribe = this.ref .where("timestamp", ">", d) .onSnapshot(this.onCollectionUpdate);

Environment

Android

  1. Build Tools:

implementation 'com.google.android.gms:play-services-base:15.0.0' implementation 'com.google.android.gms:play-services-places:15.0.0' implementation 'com.google.android.gms:play-services-location:15.0.0' implementation "com.google.firebase:firebase-core:15.0.2" implementation "com.google.android.gms:play-services-maps:15.0.0" implementation "com.google.firebase:firebase-auth:15.1.0" implementation "com.google.firebase:firebase-firestore:16.0.0"

  1. React Native version:

"react-native": "0.55.3",

  1. RNFirebase Version:

"react-native-firebase": "^4.1.0",

  1. Firebase Module:

Firestore

rikur commented 6 years ago

Hey! Just a hunch, but try playing around with with your Firestore indexes. Specifically, add an index on your timestamp field used in the query.

https://firebase.google.com/docs/firestore/query-data/indexing

KasparasGud commented 6 years ago

Hey, should the index be added only in the admin console or also in app code?

Another thing that may shed some light is that the problem happens only after uploading to google play. APK's sent via email work flawlessly and when the same apk's are uploaded to google play they break and don't fetch any data from the firestore database unless you go to settings manually and clear all app data.

KasparasGud commented 6 years ago

Rolled back to react-native-firebase “3.3.1”

And:

implementation 'com.google.android.gms:play-services-base:11.6.0' implementation 'com.google.android.gms:play-services-places:11.6.0' implementation 'com.google.android.gms:play-services-location:11.6.0' implementation "com.google.firebase:firebase-core:11.6.0" implementation "com.google.android.gms:play-services-maps:11.6.0" implementation "com.google.firebase:firebase-auth:11.6.0" implementation "com.google.firebase:firebase-firestore:11.6.0"

Everything works now.

razvanbretoiu commented 6 years ago

Same here, this happened after we upgrade the react-native-firebase to 4.1.0. The app is blocked in splash screen and don't render the entry component. It's only happening for Samsung devices.

rikur commented 6 years ago

A lot changed in 4.1.0. It also broke support for JDK9+. Makes me wonder if my Android app will work on most devices now.

aMarCruz commented 6 years ago

In my case, with rn-firebase 4.1.0 and firestore 16, I can update the data but onSnapshot(), whatever I do, is always getting the data from the cache (i.e. fromCache=true), and get() raises "The service is currently unavailable." error.

rn-firebase 4.0.7 with firestore 12.0.1 works like a charm.

razvanbretoiu commented 6 years ago

Thanks @aMarCruz , we downgrade to 4.0.7 and Firestore 12.0.0 and it's working !

chrisbianca commented 6 years ago

There have been lots of reported issues with v15 of the Android native libraries. Can I suggest you give v16 a try? Firebase released these at the end of last week: https://firebase.google.com/support/release-notes/android#20180523

aMarCruz commented 6 years ago

@chrisbianca , Last Wednesday (using 12.0.1) I inserted an "includeMetadataChanges" parameter in one of the methods to read data. This is the fragment:

  const userRef = firebase.firestore().collection('users').doc(trackedUser)

  // Monitoriza los cambios en el profile del usuario.
  const trackUnsubs = userRef.onSnapshot(
    {
      includeMetadataChanges: true,
    },
    (_doc) => {
      console.log('[trackProfile] doc:', _doc)
      dispatch(authActions.userChanged(
        _doc.exists && { ..._doc.data() } as UserProfile || null
      ))
    },
    (error) => {
      Log.e('trackProfile ERROR: ' + error.message)
      dispatch(authActions.userChanged(null, false))
    }
  ) as UnsubscribeFn

After that, I started having the same problem as with 16.0.0: functions not reaching the server; so I deleted the parameter but the error continued :(

Then I tried updating all. This is a fragment from my android/build.gradle

ext {
    googlePlayServicesVersion   = '15.0.1'
    minSdkVersion               = 21
    compileSdkVersion           = 27
    targetSdkVersion            = 27
    supportLibVersion           = '27.1.1'
    buildToolsVersion           = '27.0.3'
}

...and this is from android/app/build.gradle:

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:$rootProject.supportLibVersion"
    implementation "com.android.support:support-v4:$rootProject.supportLibVersion"
    implementation "com.facebook.react:react-native:+"         // From node_modules

    // Fiebase y otros dependen de Google Play Services
    implementation "com.google.android.gms:play-services-base:$rootProject.googlePlayServicesVersion"
    implementation "com.google.android.gms:play-services-places:$rootProject.googlePlayServicesVersion"
    implementation "com.google.android.gms:play-services-location:$rootProject.googlePlayServicesVersion"
    implementation "com.google.android.gms:play-services-maps:$rootProject.googlePlayServicesVersion"

    implementation project(':react-native-cross-settings')
    implementation project(':react-native-android-log')

    // Firebase dependencies
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-analytics:16.0.0'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.google.firebase:firebase-firestore:17.0.1'
    implementation 'com.google.firebase:firebase-storage:16.0.1'

No luck :frowning:

Then I tried deleting a field from the user profile with the console and the fun began... The field (an object with subscription dates to communities) was deleted, but after updating the page it reappeared !!!

Tried many times with the same result. This was the field:

image

Worried, I stopped trying more.

The next day (yesterday) I took a look at the App config in the Firebase console, but everything looks fine (changed nothing) so I ran the App again... and this time the App immediately updated the data that had been pending and everything worked perfectly!

I do not know what happened. I don't think it was a connection problem. Maybe a maintenance period of Firestore? the firebase status page shows something but one day before. Anyway, although my App is running fine now with the last versions, I'm still worried about these issue.

Hope this info is useful to someone.

ADDITIONAL NOTE: I'm using Android Gradle plugin 4.0.1 (com.google.gms:google-services:4.0.1) so, to avoid errors with play-services-measurement-base versions, I had to disable version checking at the end of my android/app/build.gradle:

apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

UPDATE: My problem was related to quotas:

image

I think rn-firebase is working ok, looks like Firestore is not sending the expected error.

sowdri commented 6 years ago

@chrisbianca I'm facing the same issue as well. So is it safe to update the android libraries v16.0.1? because the rnfirebase.io website still suggests version 15x of the library.

chrisbianca commented 6 years ago

v16 support is currently sitting on master - there's a few more things we need to address before we can release it.

olivierlesnicki commented 5 years ago

Facing the same issue on iOS

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent user activity. It will be closed if no further activity occurs. Thank you for your contributions.

Salakar commented 5 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.

SasiKumar-Ramesh commented 5 years ago

@Salakar We are still having the same issue. In production apps only we are getting the same error 'Firestore: The service is currently unavailable. (firestore/unavailable)' in android devices. We are using these versions

"react-native-firebase": "^4.3.0"

implementation "com.google.firebase:firebase-auth:16.0.4"
implementation "com.google.firebase:firebase-analytics:16.0.4"
implementation "com.google.firebase:firebase-core:16.0.4"
implementation "com.google.firebase:firebase-firestore:17.1.1"
implementation "com.google.firebase:firebase-database:16.0.3"
implementation "com.google.firebase:firebase-messaging:17.3.3"
implementation "com.google.firebase:firebase-perf:16.1.2"
implementation "com.google.firebase:firebase-invites:16.0.4"
implementation "com.google.firebase:firebase-ads:16.0.1" 

As mentioned above, do we need to downgrade the RN version and try? Or can we handle this error by retrying with backOff?

evelant commented 4 years ago

I think I'm also running into this issue. Unfortunately I can't reproduce it reliably.