firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
234 stars 38 forks source link

[Bug] System.AggregateException: One or more errors occurred. #811

Closed RiverTwilight closed 1 year ago

RiverTwilight commented 1 year ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

When trying to use auth.SignInAnonymouslyAsync(), an error was thrown after a very very long time, from the screenshot you can see it take 4 minutes to show the error:

Screenshot 2023-07-26 at 15 34 49

SignInAnonymouslyAsync encountered an error: System.AggregateException: One or more errors occurred. (One or more errors occurred. (An internal error has occurred.)) ---> System.AggregateException: One or more errors occurred. (An internal error has occurred.) ---> Firebase.FirebaseException: An internal error has occurred.
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.AggregateException: One or more errors occurred. (An internal error has occurred.) ---> Firebase.FirebaseException: An internal error has occurred.
   --- End of inner exception stack trace ---
---> (Inner Exception #0) Firebase.FirebaseException: An internal error has occurred.<---
<---

I'm sure I enabled the Anymonous auth method in the console, correctly set the bundle identifier, and has normal network.

Besides, the realtime component worked fine in the same project.

Steps to reproduce:

It has 100% issue repro rate, just set up in normal way.

  1. Create a new Unity project, switch to iOS platform.
  2. Add a new object in the scene, add mount this script on it.
  3. Import Auth SDK and GoogleService-Info.plist file under assets folder.
  4. Run the project.

Relevant Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase;
using Firebase.Auth;

public class Test : MonoBehaviour
{
    public FirebaseApp app;
    private FirebaseAuth auth;

    void Start()
    {
        Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
        {
            var dependencyStatus = task.Result;
            if (dependencyStatus == Firebase.DependencyStatus.Available)
            {
                app = Firebase.FirebaseApp.DefaultInstance;

                Debug.Log("Starting initilize");

                auth = Firebase.Auth.FirebaseAuth.DefaultInstance;

                auth.SignInAnonymouslyAsync().ContinueWith(task =>
                {
                    if (task.IsCanceled)
                    {
                        Debug.LogError("SignInAnonymouslyAsync was canceled.");
                        return;
                    }
                    if (task.IsFaulted)
                    {
                        Debug.LogError("SignInAnonymouslyAsync encountered an error: " + task.Exception);
                        return;
                    }

                    Firebase.Auth.AuthResult result = task.Result;
                    Debug.LogFormat("User signed in successfully: {0} ({1})",
                        result.User.DisplayName, result.User.UserId);
                });
            }
            else
            {
                UnityEngine.Debug.LogError(System.String.Format(
                "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
                // Firebase Unity SDK is not safe to use here.
            }
        });
    }
}

It will throw the error mentioned before.

What puzzles me is that my application is still able to read from and write to the Firebase Realtime Database. This leads me to believe that the issue is not network-related.

Furthermore, I have attempted several troubleshooting methods:

  1. I tried using the official Firebase Authentication example app. However, it yielded the same error, suggesting that the issue is not specific to my application.
  2. I tested the application with different Unity .NET settings, including switching to the .NET Framework, but the issue persists.
  3. As a last resort, I created a new Unity project and a new Firebase project, but unfortunately, the same issue emerged.

Given the consistency of the problem across different setups and projects, I suspect there might be a broader issue at play. I have searched extensively online but have been unable to find a solution. Any assistance in this matter would be greatly appreciated.

paulinon commented 1 year ago

Hi @RiverTwilight,

Thanks for reaching out. I understand that you're facing an internal error from the Unity editor. I've tried the code you provided, and I was able to anonymously sign in without any issue.

You mentioned that the issue persisted in a new Firebase project. Is this under the same account as the previous one? If so, could you try if a Firebase project from a different account makes any difference? I'm suspecting that the cause of the internal error may be related to your account.

RiverTwilight commented 1 year ago

@paulinon

Thanks for your help. I switched to another google account and create a new firebase project. Then I replace the google-service.plist in my Unity project and reimport the Auth SDK. Unfortunately the problem persist:

  1. It can read Realtime Databse smoothly.
  2. It cannot finish auth, and throw the same error after a very long time. It often crashed my Unity editor.

It always took around 4 minutes to thorw the same error:

Screenshot 2023-07-27 at 10 58 53

Additionaly, this error will throw even I stopped the game in Unity simulator.

AlmostMatt commented 1 year ago

@RiverTwilight I notice that you show unity console logs, and mention that the Unity editor is crashing.

Can you confirm whether you are testing this in the Unity editor's play mode (implying you are running the code on a Mac), or are you building for iOS and then testing on an iOS device? I ask this because Auth has different internal implementations for desktop vs mobile.

Additionally, to help us determine what is happening prior to the error, can you set the log level to debug and then share the logs leading up to the issue? Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug;

RiverTwilight commented 1 year ago

@AlmostMatt

Thanks for your help. I finally tried use Cloudflare's WARP and solve this issue, and my Unity editor doesn't crash anymore.

Sounds rediculous but WARP actually helps. All issue came back once I turn off WARP.

Previously I'm using ClashX as my proxy tool, and the realtime database just works fine, which make me believe the network is fine.

Anyway, thank you all for focusing this issue.