firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.23k stars 565 forks source link

Failed to get Firebase Instance ID token for fetch. FIS_AUTH_ERROR when fetching remote config #2192

Open rupinderjeet opened 3 years ago

rupinderjeet commented 3 years ago

Describe your environment

Describe the problem

At the time of doing a fetchAndActivate(), the task finishes not successful with the following exception inside:

Failed to get Firebase Instance ID token for fetch. FIS_AUTH_ERROR

This is a duplicate of #1776 with steps to reproduce

Steps to reproduce:

  1. Use a phone in airplane mode or without any SIM card.
  2. Use fetchAndActivite() on remote config instance
  3. Crash
 FATAL EXCEPTION: main
    Process: xx.rupinderjeet.xxxxxxx, PID: 475
    com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException: Firebase Installations failed to get installation auth token for fetch.
        at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.lambda$fetchIfCacheExpiredAndNotThrottled$1(ConfigFetchHandler.java:209)
        at com.google.firebase.remoteconfig.internal.ConfigFetchHandler$$Lambda$2.then(Unknown Source:8)
        at com.google.android.gms.tasks.zzg.run(com.google.android.gms:play-services-tasks@@17.0.2:2)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: com.google.firebase.installations.FirebaseInstallationsException: Firebase Installations Service is unavailable. Please try again later.
        at com.google.firebase.installations.remote.FirebaseInstallationServiceClient.createFirebaseInstallation(FirebaseInstallationServiceClient.java:200)
        at com.google.firebase.installations.FirebaseInstallations.registerFidWithServer(FirebaseInstallations.java:490)
        at com.google.firebase.installations.FirebaseInstallations.doNetworkCallIfNecessary(FirebaseInstallations.java:361)
        at com.google.firebase.installations.FirebaseInstallations.lambda$doRegistrationOrRefresh$2(FirebaseInstallations.java:351)
        at com.google.firebase.installations.FirebaseInstallations$$Lambda$4.run(Unknown Source:4)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919) 

Relevant Code:

Following call is made from onResume() of an activity. It is, also, surrounded by coroutine Dispatchers.IO using withContext()

val configSettings = remoteConfigSettings {
    minimumFetchIntervalInSeconds = 3600
    fetchTimeoutInSeconds = 40
}
remoteConfig.setConfigSettingsAsync(configSettings).await()
remoteConfig.fetchAndActivate().await()

Note: App doesn't crash if there is a SIM card and airplane mode is off (even if mobile data and WiFi is turned off)

google-oss-bot commented 3 years ago

I found a few problems with this issue:

AgiMaulana commented 3 years ago

isn't it simply because the SDK couldn't connect to the firebase service? you can wrap the fetching in a try-catch block

rupinderjeet commented 3 years ago

Well, anyone will do exactly that.

I reported because the last guy who commented on #1776 asked to reopen it if anyone encountered it. Also, they couldn't find the source of the issue.

https://github.com/firebase/firebase-android-sdk/issues/1776#issuecomment-713738642

Besides, will you want the app to crash if there's no connectivity? The documentation never mentioned that I need to do this. And, what's the point of adding something like onFailureListener or onCompleteListener?

AgiMaulana commented 3 years ago

is await() an extension function? can you give me a sneak peek of the extension? maybe that is a coroutine related issue

rupinderjeet commented 3 years ago

Ah, sure. Yes, that makes sense. await() is from following dependency.

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.1.1"
AgiMaulana commented 3 years ago

possibly the await() resume the coroutine with an exception when there is a failure

rlazo commented 3 years ago

@AgiMaulana you're right, await() will re-throw any exceptions thrown in the co-routines

https://github.com/Kotlin/kotlinx.coroutines/blob/master/integration/kotlinx-coroutines-play-services/src/Tasks.kt#L92

@ankitaj224 can comment on the specifics of the failure

sukhpalcurofy commented 3 years ago

I was facing the same issue while using multiple project config(staging and prod). If you are using double google-service.json files one for prod and one for staging environment then you should override the below string res values in staging directory string.xml file. it is working for me.

`

<string name="firebase_database_url" translatable="false"></string>

<string name="gcm_defaultSenderId" translatable="false"></string>

<string name="google_api_key" translatable="false"></string>

<string name="google_app_id" translatable="false"></string>

<string name="google_crash_reporting_api_key" translatable="false"></string>

<string name="google_storage_bucket" translatable="false"></string>

<string name="project_id" translatable="false"></string>`

you can verify or compare values of these res in this path -> build/generated/res/google-services/production/debug/values/values.xml

this is what actual values your current build is using

https://firebase.google.com/docs/projects/multiprojects#kotlin+ktx

ankitaj224 commented 3 years ago

@rlazo Regarding the Firebase Installations error: If the RC fetch was awaiting on FIS getToken method for auth token and there is no connectivity, the call will fail with the above error. I am not sure how RC internally handles that failure.

@danasilver can you please help from the RC end of things.

Thanks.

danasilver commented 3 years ago

Sure - if the getToken method fails, RC will propagate that exception and return a task with a FirebaseRemoteConfigClientException.

abbas427 commented 2 years ago

I am also getting the same issue any luck??

Firebase remote config fetch failed, details:c9.d: Firebase Installations failed to get installation auth token for fetch.

zjamshidi commented 1 year ago

Our users are still facing this error on version 21.2.1. The configs are fetched on the main activity and Google Play Services availability is checked before fetching them. I couldn't believe it is happening due to network connectivity (523 occurrences in the last 7 days). I tried disabling the wifi / mobile data but couldn't reproduce the exception.

Any thoughts or solutions?