Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Ggayane opened this issue Aug 16, 2022 · 21 comments
Closed

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

Ggayane opened this issue Aug 16, 2022 · 21 comments
Labels
help: needs-triage Issue needs additional investigation/triaging. type: bug New bug report Type: Stale Issue has become stale - automatically added by Stale bot Workflow: Waiting for User Response Blocked waiting for user response.

Comments

@Ggayane
Copy link

Ggayane commented Aug 16, 2022

[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"

@Ggayane Ggayane added help: needs-triage Issue needs additional investigation/triaging. type: bug New bug report labels Aug 16, 2022
@mikehardy
Copy link
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

@mikehardy mikehardy added the Workflow: Waiting for User Response Blocked waiting for user response. label Aug 16, 2022
@Ggayane
Copy link
Author

Ggayane commented Aug 16, 2022

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
Copy link
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
Copy link
Author

Ggayane commented Aug 16, 2022

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

@AdnanIqbalKhan
Copy link

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

@mikehardy
Copy link
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
Copy link

@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
Copy link

AdnanIqbalKhan commented Aug 29, 2022

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
Copy link

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
Copy link

github-actions bot commented Dec 5, 2022

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.

@github-actions github-actions bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Dec 5, 2022
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2022
@becabytess
Copy link

In my case , the problem was that i was trying to use offline persistence without caching the data first . So , make sure you have fetched first before trying to make use of offline-persistence .

1 similar comment
@becabytess
Copy link

In my case , the problem was that i was trying to use offline persistence without caching the data first . So , make sure you have fetched first before trying to make use of offline-persistence .

@jomgapuz
Copy link

This is still happening with the latest version "20.30.0" with iPhone SE (3rd generation) simulator and using Firebase emulators with auth and firestore. Do you have an official guide or solution for this?

@ftaibi
Copy link

ftaibi commented Aug 23, 2024

still happening

@alikrodrigues
Copy link

alikrodrigues commented Sep 1, 2024

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

@jd-alexander
Copy link

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

@Daniel-W1
Copy link

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

@francesco-clementi-92
Copy link

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
Copy link
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
Copy link

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
Copy link

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help: needs-triage Issue needs additional investigation/triaging. type: bug New bug report Type: Stale Issue has become stale - automatically added by Stale bot Workflow: Waiting for User Response Blocked waiting for user response.
Projects
None yet
Development

No branches or pull requests