firebase / firebase-android-sdk

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

com.google.firebase.FirebaseNetworkException: A network error (such as timeout, interrupted connection or unreachable host) #1985

Open bolds07 opened 3 years ago

bolds07 commented 3 years ago

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

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

My app is production with over 500k downloads on google play and some user (i dont know exactly why) have this error when logging in...

com.google.firebase.FirebaseNetworkException: A network error (such as timeout, interrupted connection or unreachable host)
       at com.tomatedigital.giveawaymaster.task.LoginTask.lambda$firebaseAuth$1(LoginTask.java:249)
       at com.tomatedigital.giveawaymaster.task.-$$Lambda$LoginTask$p6eSSF8vZ2BATwhlFttcJl8qT-w.onComplete(-.java)
       at com.google.android.gms.tasks.zzi.run(zzi.java:4)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)

there is no an easy connection between these users, different android versions, different phone models.... i found this old issue: https://github.com/firebase/firebase-android-sdk/issues/384 but seems that someone in firebase team just trew it under the carpet instead of solving it (very common here)

the error is happening in real devices in production, Some users with problem come to support and ive asked to reinstall the app but they keep error... also it is not a INTERNET CONNECTION problem because people are talking to me in an online chat and having the problem in the same time

crashlytics show it is happening in 1% of sessions... but it is always same users

Relevant Code:

FirebaseAuth.getInstance().signInWithCustomToken(token).addOnCompleteListener(AsyncTask.THREAD_POOL_EXECUTOR, task -> {
                if (task.isSuccessful()) {
                    FirebaseCrashlytics.getInstance().log("new firebase token successfully authenticated");
                } else {
                    App.shouldNeverHappen(new RuntimeException(task.getException().getMessage() + " data: " + sb.toString()));
                    this.exception = task.getException();
                }

});

//token is generated in my Firebase cloud functions as
auth.createCustomToken(uid).then(function(customToken) {
        res.status(200).send(customToken);
    }).catch(function(error) {
        console.error("Error creating custom token:" + JSON.stringify(error));
        res.status(200).json({
            e: error
        });
    });
google-oss-bot commented 3 years ago

I found a few problems with this issue:

bolds07 commented 3 years ago

3 days still NO answer... soon someone will come and say "this issue is closed due inactivity"

malcolmdeck commented 3 years ago

Hey bolds07,

We check issues about once a week - the team is small. I appreciate your patience.

As for the issue at hand, we don't have enough information to be able to triage this. Network errors like the one with the stack trace that you've posted are due to issues that happen at layers beneath the SDK - we called an API to make a network request and it failed. The fact that you say that this happens for the same users rather than randomly is interesting - it suggests that perhaps it is something specific to either the state or the hardware of their devices, but given that they have a variety of Android device models and OS levels, there's not a clear pattern that puts me in a position to investigate further.

The good news is that I can say that your code looks like it should execute properly - there are no errors in how you've written the client-side or Cloud Function code.

With the above being said, please do let us know if you find any more information that actually puts us in a position to be able to investigate further (for example, a project setup that results in the ability to reproduce this error repeatably).

Thanks, ~Malcolm

bolds07 commented 3 years ago

Unhappily this is error occurs in a high number of sessions around 1% which for my app is around 200users daily.

i've many forums talking about google play services state and relating to this but nothing conclusive.

if the engineer team which created the api and is "attached" to the responsible for the infrastructure is not able to trace the error cause it means the api lacks error info. firebase team should strongly consider add more information to the error in order to help people to solve it.

what i know.

1 - is 100% not an internet error. just before doing the auth request my app tests the users internet connection in order to avoid this type of problem 2- it is not about old devices. i got this error happening from android 5 to 9 3 - it consistly happens to same users. As i said i have a support chat in my app where users talk to me. once a girl reported this problem then i asked her to reinstall the app and restart the phone... problem still persisted... this girl complained about this error for 4 days in a row until decided stop trying to use the app

this is a screenshot of how it looks on crashlytics

https://ibb.co/hdP2r87

malcolmdeck commented 3 years ago

I understand your frustration, and appreciate you providing more detail. We'll take a look to see if there's anything we can do to help you. If you need this responded to more urgently, I advise that you contact Firebase Support.

Thanks, ~Malcolm

erichints commented 3 years ago

Hi, did you get a working solution for this? It seems that our production app is facing similar intermittent issue with authentication. If it happens to a device it seems to persist.

Thanks Eric

malcolmdeck commented 3 years ago

I don't know about the initial reporter, but I haven't received any reports of people who were able to reliably reproduce this. If you get any information that can help us resolve the issue, please do report back with some details - I would love to fix this

bolds07 commented 3 years ago

To reliably reproduce a problem that is related to some inner process of an api which i dont have access to the source nor any way to attach a debugger is very difficult

I'm still facing the problem, it is sporadic, happens in production with a range of devices... before trying to authenticate with firebase I always do 2 checks

1- ping my webserver to be sure user has internet connection 2- check if google play api is available [because i had problems that were related to this in the past]

even with both verifications i still get this issue on about 0.5% of sessions daily...

I didn't try to debug further because from my end is much easier try to find a workaround than try to debug

j22purikas commented 3 years ago

@malcolmdeck, I take over @erichints comment. Unfortunately, we are not able to reproduce it. Some users started complaining that the login spinner keeps spinning and nothing happens. That means addOnSuccessListener nor addOnFailureListener is not called(Maybe it takes a very long time before we get a callback from signInWithCustomToken, not sure, they didn't wait so long). For one user, seemed like turning on/off wifi helped to make it work(also cannot be sure 100%).

It feels like something is not working correctly, how firebase detects network connection or smth.

GEverding commented 3 years ago

@j22purikas we see similar behaviour. I opened another ticket to dive into this behaviour https://github.com/firebase/firebase-android-sdk/issues/2765

YSDC commented 1 year ago

to not let this thread die, I also posted similar issue in thread #2765

Ajohnie commented 1 year ago

We faced a similar challenge in our production app. In our case, when a user changed their network connection from WIFI to mobile data, this happened. I am not sure if this is the root cause but it was consistent among multiple users.