FirebaseNetworkException: A network error (such as timeout, interrupted connection or unreachable host)

Viewed 1604
  • Android Studio version: 3.6.3
  • Firebase Component: Auth
  • Component version: 19.4.0

I've an android app in production with over 500k downloads on google play and some users (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 correlation 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 there)

the error is happening in real devices in production, I've a small chat embebed in the app and some users with problem come to support, ive asked to reinstall the app but they keep error... also it is not an 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...

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
        });
    });
2 Answers

this issue can occur due to a few reasons

  1. LACK OF PERMISSIONS
  2. PLAY SERVICES NOT RUNNING OR FREEZED OR OUTDATED (E.G ON HUAWEI OR XIAOMI DEVICES)

Have a look at running services before launching the application if the services are frozen then unfreeze them and if they are outdated then update them and run the application again after a restart

  1. INCORRECT DATE & TIME

It might also occur if the date of the device is not correct, if the date is not correct then correct it

  1. Also occur on Mobile Data because the sometimes default data configurations have a proxy, try running on wifi to diagnose the error

Go to Project >> andriod >> right click and open new terminal in directory run command 'gradlew signingReport' and copy the SHA-1 key. Now open Firebase console >> project settings >> add fingerprint paste the SHA-1 key int here.

Related