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.63k stars 2.2k forks source link

Error: Firestore: The service is currently unavailable. (firestore/unavailable). #1441

Closed quandevelopment closed 5 years ago

quandevelopment commented 6 years ago

Issue

Environment

  1. Application Target Platform: Android

  2. Development Operating System: macOs HighSierra

  3. Build Tools:

  4. React Native version: 0.56.0

  5. React Native Firebase Version: 4.3.7

  6. Firebase Module: Firestore

  7. Are you using typescript? no

After a while a get the following error: Error: Firestore: The service is currently unavailable. (firestore/unavailable). at createErrorFromErrorData (NativeModules.js:146) at NativeModules.js:95 at MessageQueue.invokeCallback (MessageQueue.js:392) at MessageQueue.js:128 at MessageQueue.guard (MessageQueue.js:291) at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:127) at t (RNDebuggerWorker.js:1)

Then I have to deinstall and reinstall the app to get the connection again. I tried the new function
firebase.firestore().enableNetwork() but it doesn't work.

Any ideas?

Best Qung

alican-k commented 5 years ago

I encountered this error when I used a new fresh firebase project. Firestore database is also needs to be activated on the firebase console.

quandevelopment commented 5 years ago

I encountered this error when I used a new fresh firebase project. Firestore database is also needs to be activated on the firebase console.

So I have to activate Firebase Database too? It's strange because its not reproducible when the app lost the connection. But suddenly it comes online again. In the most case after I installed the app again or restart the simulator.

stale[bot] commented 5 years ago

Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

quandevelopment commented 5 years ago

Hi, I can't solved the issue so I changed to Parse as backend. It works like a charme. Now I just use the Push Server for my App. Maybe I will try it later again.

Best Qung

stale[bot] commented 5 years ago

Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

zhigang1992 commented 5 years ago

If you are located in China, FireStore / Google is blocked there.

It'll error out with firestore/unavailable

stale[bot] commented 5 years ago

Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

anhtuank7c commented 5 years ago

Hum... i face the same problem even I am not located in China

stale[bot] commented 5 years ago

Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

stale[bot] 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 having this issue in our production apps. Please check this
screenshot 2019-03-08 at 1 48 43 pm

haitranhuy commented 4 years ago

any update for this issues

pitchourou commented 4 years ago

Same here , it is a problem

joeljerushan commented 4 years ago

Someone Help this happens in some times suddenly (not every time)

image

ts-ign0re commented 4 years ago

I've got the same problem in two different applications in production.

zhigang1992 commented 4 years ago

One possibility is that it's an error message issue.

when I'm doing .get({source: 'cachce'}) and the firebase SDK will throw

Error Domain=FIRFirestoreErrorDomain Code=14 "Failed to get document from cache. (However, this document may exist on the server. Run again without setting source to FirestoreSourceCache to attempt to retrieve the document " UserInfo={NSLocalizedDescription=Failed to get document from cache. (However, this document may exist on the server. Run again without setting source to FirestoreSourceCache to attempt to retrieve the document }

But code 14 will be translated into FIRFirestoreErrorCodeUnavailable

with error message of

The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.

which is incorrect in this case.

wangxpert commented 4 years ago

Any solution here? It's really blocking production release.

amitpatelcontract commented 4 years ago

Did you guys figure this one out? Please update if anyone did. Thanks!

quantux commented 4 years ago

I'm also having the same problem :/

brandtnewlabs commented 4 years ago

I'm facing the same issue on my App in production now and then.

`Non-fatal Exception: UnhandledPromiseRejection [firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.

` Would be great to find a workaround soon.
ts-ign0re commented 4 years ago

Have the same bug [firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying wit

kadirakkaya commented 4 years ago

In my case I have array in document and there are 75 items in array. I reduced array items to 50 and error gone.

jermgilb commented 4 years ago

I get these errors randomly, if I restart the phone they tend to go away.

jbromberg commented 4 years ago

Also having this issue. Any updates?

VladRDV commented 4 years ago

Are there any updates on this issue?

mikehardy commented 4 years ago

Why would there be updates on a closed issue?

RichardFevrier commented 4 years ago

Maybe @mikehardy because it should have never been closed in the first place :)

Like @zhigang1992, I can reproduce this issue when I try to get the data from the cache. On a new device or by deactivating the persistence:

await firestore().settings({
  persistence: false,
});
mikehardy commented 4 years ago

@RichardFevrier this issue is so old, I'd recommend opening a new issue with 100% up to date versions (that is firebase-ios-sdk 6.28.1 and firebase-android-sdk BoM 25.6.0 - it's documented on rnfirebase.io how to override) to make sure we're not chasing phantoms.

You can't imagine the number of "I have the exact same problems" we get that are actually the same problem about 1% of the time, so we work with the info we have available, doing our best, and close things when they seem like the original issue is closed. With the dates on these comments so old, definitely go for a new issue with up to date versions, necessary info provided, and a repro App.js if at all possible

guiima commented 4 years ago

I had the same problem. In my case it was the settings on google-services.json that were wrong. Maybe it will help someone.

emreakcadag commented 4 years ago

It's. revelant with _firestore.disableNetwork()

When you disable network then enable again; it does not work. It keeps disabled. So that's why getting this error.

And also I could not find any solution.

mikehardy commented 4 years ago

@emreakcadag there have been several upstream issues related to this, out of our control. If you instrument the code and verify we are calling the native disable/enable network APIs then the react-native-firebase module is doing what it can. You might verify with firebase-android-sdk 25.9.0 and firebase-ios-sdk pod 6.31.0 to make sure that with up to upstream SDKs this is still happening, and check their issues lists (they are on github as well under those repo names)

melodysdreamj commented 3 years ago

I had the same issue. It was a problem because the time of the test device was 1 month ago. After correcting the time, all the problems were solved.

mikehardy commented 3 years ago

Interesting @melodysdreamj that info may help some people. It's important to note that if you are a parent with children, it's currently a "thing to try" for children to get around various parental restrictions by setting the time on their borrowed parent's phones back in time, so having incorrect times/dates set on devices happens more than you would think.

davenlin19 commented 3 years ago

Still have this problem. I tried to change the timezone, signout at the beginning of App.js but no luck :( @mikehardy do you have any idea how to fix it once for good? Thanks

lpetkov-sw commented 3 years ago

Hello, we have the same problem. Once the device loose it's network and then back it again the firestore keep returning old data. It'a using the cache without synchronizing it until the app is not reinstalled (the local storage is deleted). Please share some workarounds if you have some.

P.S. That's happening on iOS/Android simulator/emulator and devices as well.

mikehardy commented 3 years ago

The best thing to do is make sure you are using the most up to date firebase-android-sdk underling, which is I think 25.13.0 (26.0.0 won't be possible to use until #4471 lands and forward ports to the new major version of the upstream library). Information on how to override the underlying SDK version (in case you do not have the most current) is on the rnfirebase.io main page I believe

aliasad106 commented 3 years ago

It is still happening on the latest verison.

mikehardy commented 3 years ago

@aliasad106 does not move the issue forward but does generate notifications for everyone. How did it go when you tried each of detailed items in the comments above?

aliasad106 commented 3 years ago

@mikehardy I'm sorry This is my environment.

  1. React Native 0.63.3
  2. @react-native-firebase/app" 10.1.0
  3. @react-native-firebase/firestore 10.1.1
  4. Firebase region Europe London
  5. Issue experienced in Pakistan
  6. Happens when network is 2G or slower( everything else works )
mikehardy commented 3 years ago

So, you have outdated versions (likely not a cause, but still, why chase issues on old versions?) and on likely unreliable networks firestore is unavailable? That seems like expected behavior? There is all sorts of information you do not address about caching, network availability network state etc above.

TrungJamin commented 3 years ago

i got the same and here is the way i fixed it. i just run yarn add @react-native-firebase/app and yarn add @react-native-firebase/firestore I also close my simulator and wipe the data before I turn it on again and it worked for me. Hopefully it works for you guys.

mzyadatuba commented 3 years ago

This is really strange issue, yesterday everything was working just fine, now this error keeps showing

[cloud_firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.

Its really a blocker and there is not valid explanation or solution!

Why everything related to Firebase always buggy and unstable!

mikehardy commented 3 years ago

Everything related to Firebase is pretty stable and works great for me.

Sorry you're having this experience, I can understand if you suffer frequent problems it is frustrating.

I imagine you either are attempting to use a VPN that has been flagged for abuse by google and blocked, or you don't have your project set up correctly to generate tokens (like, the device check API is not enabled or is failing for some reason) so firestore no longer believe it has sufficient privileges to authenticate to the cloud backend and fails you

jonathanmv commented 3 years ago

In my case I was getting the error from the android emulator running on mac. I didn't notice that the android emulator didn't have internet connexion. I fixed it by adding a DNS Server as suggested in this StackOverflow answer.

That solved the emulator-not-having-internet issue, which then solved the firestore/unavailable issue.

abhishrek commented 3 years ago

I am having this issue on mac on Android Emulator only. iOS emulator is running fine and is able to read the exact same data. it's not the DNS or VPN issue, as it occurs randomly. Mostly it runs fine, but suddenly one rainy day, it gives the Error.

haoyuant commented 3 years ago

Having this issue on some Android devices, and it seems that this happens quite often on some of the users' phones. I believe it is related to the refresh token, but don't know how to fix it.

mikehardy commented 3 years ago

@haoyuant my first suspicion is always a VPN for firestore unavailable. If it's not that, then if your thunch about refresh tokens is right, check all the google cloud platform API access around auth tokens and device check APIs etc

haoyuant commented 3 years ago

Hi @mikehardy, I already checked the API settings, looks all good and Firebase works most of the time. All of the users reported this issue are in Australia and I believe they don't use any VPN, and their network works normally since they can use other apps without any problem. If the unavailable issue occurs, the Firebase services including Cloud Functions, Authentication(network request failed) and Firestore will fail in a row even I already implemented some sorts of retry, then the users need to restart the app to fix the problem. I don't think the app itself has some logical bugs that lead to this issue, since even the very simple Firestore query on the login page fails randomly. Only happens on Android.

mikehardy commented 3 years ago

This may need closer work with a friendly user, a native reproduction tester app from firebase-android-sdk and some careful testing / display of Auth token / refresh token status along with network availability testing / display that user could run / send results with. No idea how we could reproduce without being in situ on the affected network

haoyuant commented 3 years ago

Yea actually my client she's one of the affected user, she did run some tests for me on her phone, like I told her to switch the network and make sure the network was working well, and she tried wifi/4g/other guy's hotspot, but the same issue kept happening. According to her report, when this bug occurred, she restarted the app, but the app asked her to sign in again, so it seems that the refresh token expired somehow, which I believe is same as the issue discussed in this post https://medium.com/@chonnaronghanyawongse/coding-diary-why-my-firestore-doesnt-work-2db41fb82121

I added some code to catch the unavailable exception, and tried to get the refresh token from the cloud but in some cases (roughly 50% of the time) the request still failed 3 times in a row with roughly 3 sec retry delay for each.