firebase / firebase-android-sdk

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

Various exceptions in signInAnonymously() #944

Closed artths closed 4 years ago

artths commented 5 years ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I authenticate users anonymously with signInAnonymously() and added a log of exceptions to my server from addOnFailureListener() after many reports that something isn't working. I got 5 kinds of exceptions, none of which I could not find how to fix. It looks like a bug. Here are they:

First is the most popular. The latter is not necessarily a bug, but I do not know how they were able to send a log to the server if they do not have Internet.

Relevant Code:

FirebaseAuth.getInstance().signInAnonymously()
                    .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

                               // ...
                            }
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            // log exception to server
artths commented 5 years ago

Full stack stace for error 7: Exception: com.google.firebase.FirebaseException: An internal error has occurred. [ 7: ] at com.google.firebase.auth.api.internal.zzdx.zza(zzdx.java:18) at com.google.firebase.auth.api.internal.zzfa.zza(zzfa.java:21) at com.google.firebase.auth.api.internal.zzet.zza(zzet.java:34) at com.google.firebase.auth.api.internal.zzev.zza(zzev.java:74) at com.google.firebase.auth.api.internal.zzed.zza(zzed.java:18) at com.google.android.gms.internal.firebase_auth.zza.onTransact(zza.java:13) at android.os.Binder.execTransact(Binder.java:739)

It happens on various devices and all Android versions. Google Play Service status code is always 0 which means connection successful and Play Services is up to date. I got it with this method: https://developers.google.com/android/reference/com/google/android/gms/common/GoogleApiAvailability.html#isGooglePlayServicesAvailable(android.content.Context) So I believe it's not related to Play Services, connection or anything else.

artths commented 5 years ago

Related to https://github.com/firebase/quickstart-unity/issues/474 and https://github.com/firebase/firebase-android-sdk/issues/942

PieterPicup commented 5 years ago

Same issue with signInWithEmailAndPassword. com.google.firebase.FirebaseException: An internal error has occurred. [ 7: ] Happens randomly with a project which has been running perfectly for months. Same environment as OP

artths commented 5 years ago

In all cases error 7 happens on recent Google Play Services versions (https://developers.google.com/android/reference/com/google/android/gms/common/GoogleApiAvailability.html#GOOGLE_PLAY_SERVICES_VERSION_CODE) : 19530035 19420007 19530007 19530017 19530033 19420053 19530018 19530020 19530016 19530011 19420033 19420016 19420020 19530054 19420017

So it may be related to Play Sevices recent update.

aliguvenc commented 5 years ago

is there any progress in this issue?

artths commented 5 years ago

No, it seems. It's been 15 days since I created the report, looks like we were left with this bug alone.

aguatno commented 5 years ago

Hi @artsemionov sorry for the long wait. Currently, there are no known incidents or outages happening related to this issue. Since when did you start to notice the issue? Is there any particular pattern you notice (device model, Android API versions) that significantly contributes to the issue?

aliguvenc commented 5 years ago

Hi @aguatno I have the same issue. The problem occurs on various type of devices and android sdks not on a specific one. I am using firebase auth 19.0.0 and custom sign in method. The crash happens while executing Tasks.await method. This is how i call firebaseIdToken

FirebaseAuth.getInstance().currentUser?.let {user->
                val task = user.getIdToken(false)
                val tokenResult = Tasks.await(task)
                val idToken = tokenResult.token
}

and crash report from firebase

Caused by java.util.concurrent.ExecutionException: com.google.firebase.FirebaseException: An internal error has occurred. [ 7: ]
       at com.google.android.gms.tasks.Tasks.zzb(:61)
       at com.google.android.gms.tasks.Tasks.await(:23)
Caused by com.google.firebase.FirebaseException: An internal error has occurred. [ 7: ]
       at com.google.firebase.auth.api.internal.zzdx.zza(com.google.firebase:firebase-auth@@19.0.0:18)
       at com.google.firebase.auth.api.internal.zzfa.zza(com.google.firebase:firebase-auth@@19.0.0:21)
       at com.google.firebase.auth.api.internal.zzet.zza(com.google.firebase:firebase-auth@@19.0.0:34)
       at com.google.firebase.auth.api.internal.zzev.zza(com.google.firebase:firebase-auth@@19.0.0:74)
       at com.google.firebase.auth.api.internal.zzed.zza(com.google.firebase:firebase-auth@@19.0.0:18)
       at com.google.android.gms.internal.firebase_auth.zza.onTransact(com.google.firebase:firebase-auth@@19.0.0:13)
       at android.os.Binder.execTransact(Binder.java:739)
artths commented 5 years ago

Hi @artsemionov sorry for the long wait. Currently, there are no known incidents or outages happening related to this issue. Since when did you start to notice the issue? Is there any particular pattern you notice (device model, Android API versions) that significantly contributes to the issue?

I use latest auth SDK (19.1.0). I started to notice this issue once I begin to use Firebase auth about month ago. But some people say they had it working great for a months, and then a problem started to arise. I do not know how you may not know about this problem, since it is not rare. I have about 2k reports a day affecting 1k users (50-60k daily users). The only pattern I found is the recent Google Play Services version. It happens on various devices, even top one (Samsung S10+) and all Android versions my app supports (>= 5.0). The other errors I mentioned in this thread clearly connected with old Google Play Services on device, as I clearly see they are outdated.

aguatno commented 5 years ago

Thanks for the information @artsemionov. I ran a test but didn't get the crash or error message. Can you help me reproduce the error? If you could provide a minimal repro of your app that I can run locally, that would be a great help for us to speed up the investigation. Thanks

artths commented 5 years ago

I would love to help you if I could reproduce the bug. The problem is that it always works perfectly for me, unlike many of my users. You can create a simple project and authorize the user anonymously. Here is my method:

    public interface OnSignInListener
    {
        void onSuccess();
        void onFailure();
    }

    static void signIn(final OnSignInListener listener) {
        Crashlytics.log("signIn");

        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

        if(user != null) {
            listener.onSuccess();
            Crashlytics.log("signIn signInAnonymously success");
        }
        else {
            FirebaseAuth.getInstance().signInAnonymously()
                    .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

                                if(user != null) {
                                    listener.onSuccess();
                                    Crashlytics.log("signIn signInAnonymously success");
                                }
                                else {
                                    listener.onFailure();
                                }
                            }
                            else {
                                listener.onFailure();
                            }
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Crashlytics.log("signIn signInAnonymously failure");
                            Crashlytics.logException(e);
                        }
                    });
        }
    }

And look what I got in Crashlytics: 2019-11-12_225753_console firebase google com

I would check the source of the Auth SDK and Play Services if I could.

artths commented 5 years ago

I'm going to cut out Firebase as an unstable product. If you need more info about bug this is just the time.

artths commented 5 years ago

Same exception happens when I try to get user id token, after the successful authorization:

            FirebaseAuth.getInstance().signInAnonymously()
                    .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

                                user.getIdToken(false).addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
                                    public void onComplete(@NonNull Task<GetTokenResult> task) {
                                        if (task.isSuccessful()) {
                                            listener.onSuccess(task.getResult().getToken());
                                            Crashlytics.log("getToken getIdToken success");
                                        } else {
                                            listener.onFailure();
                                        }
                                    }
                                })
                                .addOnFailureListener(new OnFailureListener() {
                                    @Override
                                    public void onFailure(@NonNull Exception e) {
                                        Crashlytics.log("getToken getIdToken failure");
                                        Crashlytics.logException(e);
                                    }
                                });
                            } else {
                                listener.onFailure();
                            }
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Crashlytics.log("getToken signInAnonymously failure");
                            Crashlytics.logException(e);
                        }
                    });
        }

It happens even more often than failed signInAnonymously.

D/CrashlyticsCore getToken getIdToken failure

Non-fatal Exception: com.google.firebase.e: An internal error has occurred. [ 7: ]
       at com.google.firebase.auth.api.internal.zzdx.zza(zzdx.java:18)
       at com.google.firebase.auth.api.internal.zzfa.zza(zzfa.java:21)
       at com.google.firebase.auth.api.internal.zzet.zza(zzet.java:34)
       at com.google.firebase.auth.api.internal.zzev.zza(zzev.java:74)
       at com.google.firebase.auth.api.internal.zzed.zza(zzed.java:18)
       at com.google.android.gms.internal.firebase_auth.zza.onTransact(zza.java:13)
       at android.os.Binder.execTransact(Binder.java:454)

Sometimes user successfuly gets token, but fails to do it in a few seconds on a new request.

One time user got onComplete() listener fired after 20 minutes after the getIdToken()....

artths commented 5 years ago

Found a post with similar issue: https://medium.com/@chonnaronghanyawongse/coding-diary-why-my-firestore-doesnt-work-2db41fb82121 Tried do the same: disable and re-enable the Token Service API. And seems it helped because I'm not getting a single report for a few hours... LOL

artths commented 5 years ago

Nope, it's back. Seems crashlytics had a few hours delay.

aliguvenc commented 5 years ago

@artsemionov May it be related to regenerating idToken after it has expired? You are calling idToken method without forcing new token right? Have you tried to force new id token every time you need ?

artths commented 5 years ago

Yes, I do not force new token. It seems a bad idea, because doing it in production means users will have 2 seconds delay on each request to my server. The problem may be related to expired id token, however besides getting this exception on getIdToken() I also get it on signInAnonymously(). I found that new error code added in exception, and sometimes I get "An internal error has occurred. [ 13: ]" instead of [ 7: ]. Can someone from team just check the source code and tell what these error codes mean? Sometimes I just get // some html code Your client does not have permission to get URL /identitytoolkit/v3/relyingparty/signupNewUser from this server Just like in this issue: https://github.com/firebase/firebase-android-sdk/issues/942

artths commented 5 years ago

@aliguvenc Just tested token regenerating. Firebase does it on its own 5 minutes before expire. All works as intended.

aliguvenc commented 5 years ago

so if you force to refresh token, it still returns cached one if it has not expired?

artths commented 5 years ago

No, if you force it you get new token. But if you do not, Firebase will force it automatically 5 minutes before expire.

aguatno commented 5 years ago

@artsemionov thanks for waiting. I was able to reproduce the error using S10+. I get this error while testing the Android Quickstart and addOnFailureListener. Then disabling my mobile internet connection and trying to login and the result is "An internal error has occurred. [ 7: ]"

image

I'm currently confirming to the team if this is really a network issue. I'll get back to you with more updates.

artths commented 5 years ago

Hi, Was you able to reproduce it on other devices? I did try to turn off network and I constantly get a "A network error (such as timeout, interrupted connection or unreachable host) has occurred." exception on emulator and device. What about "An internal error has occurred. [ 13: ]" and "Your client does not have permission to get URL /identitytoolkit/v3/relyingparty/signupNewUser from this server"? If it's really caused by a network connection then this error is the most misleading I've only seen.

aliguvenc commented 5 years ago

Hİ @artsemionov and @aguatno i simply put my device on airplane mode and started my app and i reproduced error but there is one thing that i want to point. When i put my device on airplane mode my token was already expired because i haven't launched my app since yesterday afternoon. But after disabling airplane mode and and taking my id token from firebase and re-enabling airplane mode didn't reproduce the error

artths commented 4 years ago

Hi, any progress on this?

aguatno commented 4 years ago

The issue has been identified and fixed. However, I may not be able provide you with any specifics as to when will the fix be released in production. For now, try to catch the issue manually. Once the fix goes live, you'll not need to update to the new SDK version.

I'll close this when the fix is in prod.

aguatno commented 4 years ago

Issue confirmed as a network connection error.

kanoblake commented 4 years ago

Any updates here? I have an application going live very shortly and we are experiencing a high rate of this in our onboarding funnel. At least 4 - 5% of our new android users are getting this and dropping off, which is extremely expensive.

aguatno commented 4 years ago

Thanks for patiently waiting. I got confirmation from our engineering team that this issue has been fixed externally. They just need to be using the newest release of Google Play services. SDK upgrade will not be needed.

Closing this issue, please let us know if it's still happening and we can re-open it.