Skip to content

[firestore/unavailable] The service is currently unavailable #6474

Not planned
@Ggayane

Description

@Ggayane

[firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff, this error appears, although there is a network connection, this happens a lot on Android devices, and a few times on iOS.
Does anyone know what can be the problem?
I've found similar reports in issues section, but they don't seem to have any solution.

I'm using "@react-native-firebase/firestore": "^14.2.2"

Activity

mikehardy

mikehardy commented on Aug 16, 2022

@mikehardy
Collaborator

In my experience, usually Google Compute Platform does not like the client's network endpoint (blocklisted VPN IP address or similar) or the network is down, or API keys are restricted or similar.

Impossible to say without being able to definitely reproduce it with knowledge of the client's network environment, and knowledge of the google computer platform / firebase project / API key configuration

Ggayane

Ggayane commented on Aug 16, 2022

@Ggayane
Author

I've tested on the same network both iOS and Android, iOS works fine, on Android sometimes I see this error, and whenever this happens right after it when I try another request (like firestore().doc(smoething).get();) it works as expected, without any errors. And I also check user token while this error appears, token is fine and not expired.

mikehardy

mikehardy commented on Aug 16, 2022

@mikehardy
Collaborator

That's odd - I wonder if the android device is somehow putting the network to sleep aggressively, for instance for power-saving.

It appears to be this case from the error message:

This is a most likely a transient condition and may be corrected by retrying with a backoff

Ggayane

Ggayane commented on Aug 16, 2022

@Ggayane
Author

that's possible I guess, the solution can be to catch this error and retying to do the same call again.

AdnanIqbalKhan

AdnanIqbalKhan commented on Aug 17, 2022

@AdnanIqbalKhan

I am getting the same issue
using @react-native-firebase/firestore": "^14.7.0"

mikehardy

mikehardy commented on Aug 24, 2022

@mikehardy
Collaborator

@AdnanIqbalKhan you assert

I am getting the same issue

...but providing no evidence to back up the assertion

Troubleshooting requires precision, accuracy, and details. In the future please do not "metoo" post on other people's details unless you are certain based on concrete evidence you have the same issue.

The original poster has provided some logging indicating it may be that the app is having a transient network connectivity issue.

No one has reported followup information where details about the network environment at the time of the error are provided, so we just have a hypothesis right now and are waiting for details

AdnanIqbalKhan

AdnanIqbalKhan commented on Aug 24, 2022

@AdnanIqbalKhan

@mikehardy I don't know what causes the issue
in a physical device, it works fine
but in the emulator firebase/auth is working but firebase/firestore and firebase/database not responding
This is the error I get.
"[Error: [firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.]"

AdnanIqbalKhan

AdnanIqbalKhan commented on Aug 29, 2022

@AdnanIqbalKhan

The problem is with Android Emulator v 31.3.10 Turning off wifi in the emulator and turning on its data connection works for me. Check these for further details.

Firebase doesn't work on Android Studio Emulator

raulgordejev

raulgordejev commented on Sep 30, 2022

@raulgordejev

I've had the same problem for years with react-native-firebase. What happens (I think) is that OS battery saver/optimisation settings kill the firestore connection while the app is backgrounded for some time (a few minutes). After opening the app again, firestore takes quite a long time to reconnect - around 30 seconds up to 1 minute. Get queries return the [firestore/unavailable] error, but subscriptions just silently wait until firestore is reconnected.

It's been a really annoying issue to deal with and I haven't seen any proper solutions for that yet. As a workaround I'm currently using firestore REST API to fetch data in addition to subscriptions in the more critical places in the app.

From crashlytics logs it seems to be happening slightly more on iOS, but I've found it to be easier to reproduce on Android. Specifically Androids 10 to 12.

To reproduce this issue:

  1. Subscribe to a collection/document in the app
  2. Put the app in the background state
  3. Settings->Battery->Battery saver [on] OR Select your app -> App info -> Battery -> Manage battery usage [restricted]
  4. Open the app after around 5 minutes
  5. Firestore subscription should not return anything for around 30 seconds and get queries will return [firestore/unavailable].
github-actions

github-actions commented on Dec 5, 2022

@github-actions

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.

added
Type: StaleIssue has become stale - automatically added by Stale bot
on Dec 5, 2022

3 remaining items

ftaibi

ftaibi commented on Aug 23, 2024

@ftaibi

still happening

alikrodrigues

alikrodrigues commented on Sep 1, 2024

@alikrodrigues

Still happening it a lot of times, most of the times in android OnePlus8
image

jd-alexander

jd-alexander commented on Sep 2, 2024

@jd-alexander

For me the error was taking place due to some WiFi issues. When I switched to another network it disappeared.

Daniel-W1

Daniel-W1 commented on Sep 26, 2024

@Daniel-W1

has anyone fixed this issue, it happened to me too, and I couldn't find any fix.

francesco-clementi-92

francesco-clementi-92 commented on Oct 16, 2024

@francesco-clementi-92

I've had the same problem for years with react-native-firebase. What happens (I think) is that OS battery saver/optimisation settings kill the firestore connection while the app is backgrounded for some time (a few minutes). After opening the app again, firestore takes quite a long time to reconnect - around 30 seconds up to 1 minute. Get queries return the [firestore/unavailable] error, but subscriptions just silently wait until firestore is reconnected.

It's been a really annoying issue to deal with and I haven't seen any proper solutions for that yet. As a workaround I'm currently using firestore REST API to fetch data in addition to subscriptions in the more critical places in the app.

From crashlytics logs it seems to be happening slightly more on iOS, but I've found it to be easier to reproduce on Android. Specifically Androids 10 to 12.

To reproduce this issue:

  1. Subscribe to a collection/document in the app
  2. Put the app in the background state
  3. Settings->Battery->Battery saver [on] OR Select your app -> App info -> Battery -> Manage battery usage [restricted]
  4. Open the app after around 5 minutes
  5. Firestore subscription should not return anything for around 30 seconds and get queries will return [firestore/unavailable].

Hello, I'm experiencing the same error. Is there a way to check if the connection has been restored or not?

mikehardy

mikehardy commented on Oct 16, 2024

@mikehardy
Collaborator

perhaps

https://reactnative.dev/docs/appstate#addeventlistener

listen for transition to foreground, do a test get to firestore and if it is unavailble try a pair of calls to toggle the network down then up

https://rnfirebase.io/reference/firestore#disableNetwork / https://rnfirebase.io/reference/firestore#enableNetwork

I have not tried this but something like this might work

If there is no way to force the network to reinit and you must wait, then in the app could also maintain a global "firestore network is available" status flag somewhere, and in the AppState listener on transition to foreground you could try a firestore doc get and update the availability flag based on the result, testing it in a loop until it is available. Use the availability flag in other areas to do what makes sense for your app's use cases...

amarinsam

amarinsam commented on Nov 22, 2024

@amarinsam

For me, I had named my Firestore database to something other than (default). Deleting the database, and creating a new one named (default) fixed the error.

sarnakov

sarnakov commented on Dec 22, 2024

@sarnakov

For me, I had named my Firestore database to something other than (default). Deleting the database, and creating a new one named (default) fixed the error.

At first I thought it was a joke, but apparently it's a solution...

Sneidon

Sneidon commented on Jan 6, 2025

@Sneidon

For me, I had named my Firestore database to something other than (default). Deleting the database, and creating a new one named (default) fixed the error.

This fixed the issue for me.

ErangaD

ErangaD commented on Apr 12, 2025

@ErangaD

For me, I had named my Firestore database to something other than (default). Deleting the database, and creating a new one named (default) fixed the error.

this works lol

hungtooc

hungtooc commented on Apr 13, 2025

@hungtooc

For me, I had named my Firestore database to something other than (default). Deleting the database, and creating a new one named (default) fixed the error.

Fixed for me!

dogankablan

dogankablan commented on Apr 25, 2025

@dogankablan

It's really weird, but it worked.Firebase definitely needs to find a proper solution for this.

jerryphm

jerryphm commented on Apr 27, 2025

@jerryphm

I encountered the same issue when reading from firestore, both in a Cloud Function and in mobile app. Specifying the database name when calling getFirestore fixed the error for me:

import { getFirestore, doc, getDoc } from '@react-native-firebase/firestore';
import { getApp } from '@react-native-firebase/app';

const db = getFirestore(getApp(), 'my-database-name');
ngothanhtai

ngothanhtai commented on May 19, 2025

@ngothanhtai

for my case, I haven't clicked Create database in Firebase console.

TheRealMikeD

TheRealMikeD commented on May 28, 2025

@TheRealMikeD

FWIW, I see this error from time to time on my iPhone 13, which I use as my main dev/testing device. I also have NordVPN running on that phone, which might be contributing to the issue, although that's not 100% verified. I just notice that I don't ever get the error, and data loads more quickly, if I have the VPN turned off.

I also use Sentry in my app, and I do occasionally get Sentry reports of this error in the wild. In those cases, I can't really tell if the users have a VPN on their phones or not.

My solution has been twofold:

  1. Do as the error message suggests: implement a system of retries, backing off gradually.
  2. After a reasonable timeout period (and what constitutes "reasonable" changes, depending on the specific data operation), I just present a friendly error message to the user, along with a "Retry" button. In my testing, since implementing this, I get the timeout fairly often on my test device, but the manual retry (when the user clicks the "Retry" button) has worked 100% of the time, up to this point.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: StaleIssue has become stale - automatically added by Stale botWorkflow: Waiting for User ResponseBlocked waiting for user response.help: needs-triageIssue needs additional investigation/triaging.type: bugNew bug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ngothanhtai@mikehardy@jomgapuz@jd-alexander@sarnakov

        Issue actions

          [firestore/unavailable] The service is currently unavailable · Issue #6474 · invertase/react-native-firebase