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

IOException SERVICE_NOT_AVAILABLE FirebaseMessaging #4053

Open
claucookie opened this issue Sep 2, 2022 · 12 comments
Open

IOException SERVICE_NOT_AVAILABLE FirebaseMessaging #4053

claucookie opened this issue Sep 2, 2022 · 12 comments
Labels

Comments

@claucookie
Copy link

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

@google-oss-bot
Copy link
Contributor

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

@argzdev
Copy link
Contributor

argzdev commented Sep 2, 2022

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.

@claucookie
Copy link
Author

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

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.

@argzdev
Copy link
Contributor

argzdev commented Sep 2, 2022

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.

@claucookie
Copy link
Author

Thanks @argzdev , looking forward to your response :)

@argzdev
Copy link
Contributor

argzdev commented Sep 12, 2022

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 argzdev added type: feature request New feature or request and removed needs-attention labels Sep 12, 2022
@claucookie
Copy link
Author

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.

@argzdev
Copy link
Contributor

argzdev commented Sep 12, 2022

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

@si-ankush-yadav
Copy link

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.

@argzdev
Copy link
Contributor

argzdev commented Mar 30, 2023

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.

@filipatbnp
Copy link

@argzdev who are "our engineers"?

@argzdev
Copy link
Contributor

argzdev commented May 9, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants