firebase-android-sdk icon indicating copy to clipboard operation
firebase-android-sdk copied to clipboard

IOException SERVICE_NOT_AVAILABLE FirebaseMessaging

Open claucookie opened this issue 3 years ago • 8 comments

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs in the code in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:

  • For general technical questions, post a question on StackOverflow with the firebase tag.
  • For general Firebase discussion, use the firebase-talk google group.
  • For help troubleshooting your application that does not fall under one of the above categories, reach out to the personalized Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: 2021.1 Patch 1
  • Firebase Component: com.google.firebase:firebase-messaging ( Firebase Messaging )
  • Component version: 23.0.3

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

Hi! We are experiencing a crash when trying to get the token for Firebase Cloud Messaging. This is happening in production, for some users only, Samsung and Nokia devices, but we are not able to reproduce it when downloading the app on our side or deploy from Android Studio.

The stacktrace is as follows:

Caused by java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: SERVICE_NOT_AVAILABLE
       at com.google.firebase.messaging.FirebaseMessaging.blockingGetToken(FirebaseMessaging.java:620)
       at com.google.firebase.messaging.FirebaseMessaging.lambda$getToken$4(FirebaseMessaging.java:387)
       at com.google.firebase.messaging.FirebaseMessaging$$InternalSyntheticLambda$0$2fd74daaa9547626a2178c157d189c0e094dccccb61fc5ee6d886ccc44d7a00a$0.run$bridge(FirebaseMessaging.java:22)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@18.0.0:2)
       at java.lang.Thread.run(Thread.java:919)

We know the Devices crashing contains Google Play Services, as we have them in house for testing as well. What other reasons could throw SERVICE_NOT_AVAILABLE?

Relevant Code:

We use a particular setup. Apart from our default Firebase Project, we have a 3rd party restriction to connect to a secondary Firebase project to receive push notifications (FCM).

// Initialization Code for the secondary Firebase Project used to receive push notifications.
Firebase.initialize(
            context = appContext,
            FirebaseOptions.Builder()
                .setApiKey(apiKey)
                .setProjectId(projectId)
                .setApplicationId(applicationId)
                .setGcmSenderId(senderId)
                .build(),
            INSTANCE_KEY
        )
        val firebaseApp = FirebaseApp.getInstance(INSTANCE_KEY)
        val firebaseMessaging = firebaseApp.get(FirebaseMessaging::class.java) as FirebaseMessaging
        Preconditions.checkNotNull(firebaseMessaging, "Firebase Messaging component is not present")

// The code trying to obtain the token
firebaseMessaging.token.addOnCompleteListener { task ->
            if (!task.isSuccessful) {
                continuation.resume(Result.failure())
            } else {
                continuation.resume(Result.success())
            }
        }

Any help is more than welcome.

claucookie avatar Sep 02 '22 09:09 claucookie

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Sep 02 '22 09:09 google-oss-bot

Thanks for reporting, @claucookie. The SERVICE_NOT_AVAILABLE can happen for the following possible reasons:

  1. The phone is offline.
  2. The phone is online but it cannot reach Google servers.
  3. The firebase messaging servers are temporary unavailable.
  4. Google Play services is in an extremely bad state. ~5. Google Play services is not installed on the phone.~ (Since you've mentioned the crashing devices contains Google Play)

How many % of your DAU are experiencing the crash? Could it be due to intermittent internet connection by the users?

Just some notes here: I wonder if this could be related to #3987, however, it might not be since you're not using any multi sender processes.

argzdev avatar Sep 02 '22 10:09 argzdev

Thanks @argzdev for your quick response. Regarding your question:

  • This is affecting 10% of our Daily Active Users at the moment. I also wonder if it could be related to #3987 however, it shouldn't since we don't use senderId when setting up a secondary FCM project.

Could you confirm if having multiple projects setup is still supported? In the related issue it is mentioned that some features might not be supported and there is not documentation around it, so I wonder if this could be also happening as well.

claucookie avatar Sep 02 '22 11:09 claucookie

Could you confirm if having multiple projects setup is still supported?

Let me consult with our engineers about that and get back to you.

As for the documentations, we apologize for that. We're still working with our technical writer to update the public documentations.

argzdev avatar Sep 02 '22 11:09 argzdev

Thanks @argzdev , looking forward to your response :)

claucookie avatar Sep 06 '22 07:09 claucookie

Sorry for the delayed response, @claucookie. I've communicated with our engineer. It was confirmed that due to the migration to FIS, any multiple project setup related to FCM may not work properly, including multi-sender setup.

Though that said, what we can do is mark this as a feature request, and our engineers may consider discussing this further in the future. If it's alright with you, could you share what use case do you have for setting up two firebase project for one app? It may help our engineers consider why we need multiple project setup for FCM. Thanks in advance!

argzdev avatar Sep 12 '22 09:09 argzdev

Thanks @argzdev, Im fine with feature request label and happy to answer any questions from the engineers when looking into this.

The use case comes from a Third Party restriction. We had Firebase already setup in our android app for a long time ago, and our server was sending us push notifications successfully via FCM (project 1). However we recently had to include a 3rd party library (customer care library with push notifications feature) which account was linked already to another FCM account (project 2) and couldn't be changed.

That's why we had to add a secondary FCM project setup only to receive push notifications inside that third party library.

claucookie avatar Sep 12 '22 14:09 claucookie

That does sound like a reasonable use case. Thank you for sharing, @claucookie!

argzdev avatar Sep 12 '22 17:09 argzdev

Hi @argzdev @claucookie we are facing the same issue and I did able to replicate the crash on older device.

turns out when addOnCompleteListener is throwing ClassNotFoundException Exception on API level less than 23. Hope this help and we can come up with solution.

si-ankush-yadav avatar Mar 29 '23 21:03 si-ankush-yadav

Hi @ankush-yadav1, we've had discussions with our engineers, and it was communicated that since FirebaseApp.get() is annotated with @KeepForSdk.

@KeepForSDK marks methods in the SDK that are not part of the public API, and should only be used by other Firebase SDKs. There are no guarantees on how this functionality will be maintained; it can be kept or removed or changed as the need arises.

So it is no longer recommended to use this. That said, I've confirmed with our engineers that the recommended alternative solution for now is using firebase-iid, as long as the most recent versions of firebase-messaging and firebase-iid is used.

argzdev avatar Mar 30 '23 09:03 argzdev

@argzdev who are "our engineers"?

filipatbnp avatar May 05 '23 17:05 filipatbnp

Hi @filipatbnp, our engineers would pertain to Firebase product engineers. In this case, specifically, our Firebase Cloud Messaging and Firebase Core team engineers.

argzdev avatar May 09 '23 10:05 argzdev