firebase-unity-sdk icon indicating copy to clipboard operation
firebase-unity-sdk copied to clipboard

[Bug] Query fails to return only in Unity SDK. Works in Node.js

Open chriswalz opened this issue 1 year ago • 8 comments

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2021.3.33
  • Firebase Unity SDK version: 11.6 (tested on 11.4 as well)
  • Source you installed the SDK: Unity Package Manager
  • Problematic Firebase Component: Firebase.Firestore
  • Other Firebase Components in use: Firebase.App, Firebase.Analytics, Firebase.Firestore
  • Additional SDKs you are using: Oculus SDK
  • Platform you are using the Unity editor on: Windows
  • Platform you are targeting: Android
  • Scripting Runtime: IL2CPP

[REQUIRED] Please describe the issue here:

Extremely odd bug that only happens in the Unity Firestore SDK and does NOT happen in Node.js.

"ContinueWithOnMainThread" Callback never happens serverCollection().WhereGreaterThanOrEqualTo("count", 1).GetSnapshotAsync().ContinueWithOnMainThread(task2 =>

"ContinueWithOnMainThread" Callback DOES occur serverCollection().WhereGreaterThanOrEqualTo("count", 2).GetSnapshotAsync().ContinueWithOnMainThread(task2 =>

Steps to reproduce:

Aside from calling the above code. The data for the collection is structured like this:

Example data: { "count": 3 "timestamp: FieldValue.ServerTimestamp } Callback never happening is confirmed via Debugger breakpoint AND debug console logs not happening.

Relevant Code:

"ContinueWithOnMainThread" Callback never happens serverCollection().WhereGreaterThanOrEqualTo("count", 1).GetSnapshotAsync().ContinueWithOnMainThread(task2 =>

"ContinueWithOnMainThread" Callback DOES occur serverCollection().WhereGreaterThanOrEqualTo("count", 2).GetSnapshotAsync().ContinueWithOnMainThread(task2 =>

chriswalz avatar Dec 28 '23 01:12 chriswalz

Hi @chriswalz,

I've tried both lines of code that you provided, but the query succeeds either way. Are you noticing this behavior in both the Android build and the Unity editor?

Could you provide a minimal, reproducible example of your implementation so we can identify what's causing this issue?

paulinon avatar Dec 28 '23 09:12 paulinon

Hi @chriswalz,

I've tried both lines of code that you provided, but the query succeeds either way. Are you noticing this behavior in both the Android build and the Unity editor?

Could you provide a minimal, reproducible example of your implementation so we can identify what's causing this issue?

It's in the Unity Editor. I haven't tested in Android as of yet. Regarding the repro can you send me the repro you used that's working? I'll take a look. Any ideas on why ContinueWithOnMainThread silently fails in general. It's not the first it's happened and we're using LogExceptionIfFaulted

chriswalz avatar Dec 28 '23 20:12 chriswalz

Any ideas on why ContinueWithOnMainThread silently fails in general.

Have you enabled debug logging on the FirebaseFirestore instance? If you enable debug logging and provide the logs, that may give us more insight into why you are seeing this behavior without having a minimal, reproducible example.

MarkDuckworth avatar Dec 28 '23 21:12 MarkDuckworth

Any ideas on why ContinueWithOnMainThread silently fails in general.

Have you enabled debug logging on the FirebaseFirestore instance? If you enable debug logging and provide the logs, that may give us more insight into why you are seeing this behavior without having a minimal, reproducible example.

I did some more investigating and it seems related to pulling a large amount of documents roughly 500-1000 is where it seems to falter in my case

chriswalz avatar Dec 29 '23 01:12 chriswalz

The FirebaseFirestore logs don't appear to log anything when the ContinueOnMainThread callback never returns

chriswalz avatar Dec 29 '23 01:12 chriswalz

Hi @chriswalz,

Here's the code I used during my initial testing. In this case, only two queries are performed whenever the function is called.

public class FirestoreQuery : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
        {
            var dependencyStatus = task.Result;
            if (dependencyStatus == Firebase.DependencyStatus.Available)
            {
                // Create and hold a reference to your FirebaseApp,
                // where app is a Firebase.FirebaseApp property of your application class.
                GetQuery();

                // Set a flag here to indicate whether Firebase is ready to use by your app.
            }
            else
            {
                UnityEngine.Debug.LogError(System.String.Format(
                  "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
                // Firebase Unity SDK is not safe to use here.
            }
        });

    }

    void GetQuery()
    {
        FirebaseFirestore db = FirebaseFirestore.DefaultInstance;
        CollectionReference collectionRef = db.Collection("collection");
        collectionRef.WhereGreaterThanOrEqualTo("count", 1).GetSnapshotAsync().ContinueWithOnMainThread(task2 =>
        {
            Debug.Log("count1 debug log");
        });
        collectionRef.WhereGreaterThanOrEqualTo("count", 2).GetSnapshotAsync().ContinueWithOnMainThread(task2 =>
        {
            Debug.Log("count2 debug log");
        });
    }
}

I found a blog post that makes use of coroutines along with other ways to deal with asynchronous logic as an alternative to the ContinueWithOnMainThread method. Could you confirm if any of these solutions made a difference?

When using coroutines, you can add something like this in an IEnumerator block: yield return new YieldTask(serverCollection().WhereGreaterThanOrEqualTo("count", 1).GetSnapshotAsync());

paulinon avatar Jan 02 '24 17:01 paulinon

It does not appear to make a difference unfortunately. This is basic stuff. This should "just" work. Why is the Unity Firestore SDK so unstable?

chriswalz avatar Jan 04 '24 22:01 chriswalz

@chriswalz, Thanks for testing the suggestion from @paulinon. When you say the "FirebaseFirestore logs don't appear to log anything when the ContinueOnMainThread callback never returns", are you saying that there is nothing in the logs at all, or nothing in the logs that indicate an error? If anything is written to the Firestore SDK logs, we would like to also take a look at them to see if we can help diagnose.

MarkDuckworth avatar Jan 08 '24 18:01 MarkDuckworth

Hi folks, just to move this forward. Since we're unable to reproduce this same behavior on our side. It's difficult to say what's causing the issue without getting the full picture of your setup. Could you provide a minimal reproducible example or logs, @chriswalz for us to investigate this further.

argzdev avatar May 14 '24 11:05 argzdev

@MarkDuckworth There were no logs at all. @argzdev We stopped using this SDK due to its multitude of problems. I warn anyone from using this in development let alone using it in production.

For anyone reading this who is looking for alternatives Supabase is probably your best bet.

chriswalz avatar May 15 '24 16:05 chriswalz

Thanks for letting us know, @chriswalz. If ever you'd come around using our products again, feel free to open new issues in the future. We'll definitely try and work out these issues to further improve our products. That said, I'll go ahead and close this thread as "can't repro". We can always reopen this thread if ever we come back for this issue. Thanks!

argzdev avatar May 15 '24 17:05 argzdev