firebase / firebase-unity-sdk

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

[Bug] Persistent connection error thrown when using Unity 2022 on Mac #1023

Open lmt385 opened 1 month ago

lmt385 commented 1 month ago

Description

When setting up or triggering ValueChanged callbacks for a DatabaseReference, errors are being thrown by the SDK in Unity Editor. These errors only occur to our Mac machines, Windows machines and Android devices are unaffected.

The ValueChanged callbacks can be triggered, but they can then cause the same error that occurred when setting up the listener.

Originally observed this on Firebase version 10.7, upgraded to 11.9.0 and issue is still present.

Reproducing the issue

  1. DatabaseReference is obtained for a particular node in the Firebase Realtime Database
  2. A ValueChanged callback is added to the DatabaseReference object
  3. Error is triggered referencing persistent_connection.cc
  4. If a corresponding value is changed in the Firebase Realtime Database, the callback is triggered and so is the error. The callback is executed successfully.

Firebase Unity SDK Version

11.9.0

Unity editor version

2022.3.23f1

Installation Method

.unitypackage

Problematic Firebase Component(s)

Database

Other Firebase Component(s) in use

Analytics, Authentication, Storage

Additional SDKs you are using

Azure Speech, AWS

Targeted Platform(s)

Android

Unity editor platform

Mac

Scripting Runtime

IL2CPP

Release Distribution Type

Pre-built SDK from https://firebase.google.com/download/unity

Relevant Log Output

/Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/firebase-cpp-sdk/database/src/desktop/connection/persistent_connection.cc(367): listens_.find(query_spec) == listens_.end()
UnityEngine.Debug:LogError (object)
Firebase.Platform.FirebaseLogger:LogMessage (Firebase.Platform.PlatformLogLevel,string) (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/platform/Unity/FirebaseLogger.cs:95)
Firebase.LogUtil:LogMessage (Firebase.LogLevel,string) (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/src/LogUtil.cs:69)
Firebase.LogUtil:LogMessageFromCallback (Firebase.LogLevel,string) (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/src/LogUtil.cs:77)
Firebase.AppUtil:PollCallbacks () (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/android_unity/armeabi-v7a/app/swig/Firebase.App_fixed.cs:4869)
Firebase.Platform.FirebaseAppUtils:PollCallbacks () (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/platform/FirebaseAppUtils.cs:33)
Firebase.Platform.FirebaseHandler:Update () (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/platform/Unity/FirebaseHandler.cs:208)
Firebase.Platform.FirebaseMonoBehaviour:Update () (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/platform/Unity/FirebaseMonoBehaviour.cs:45)

If using CocoaPods for Apple platforms, the project's Podfile.lock

Expand Podfile.lock snippet
```yml 👀 Replace this line with the contents of your Podfile.lock! ```
google-oss-bot commented 1 month ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

argzdev commented 1 month ago

Hey @lmt385, thanks for reaching out. I'm trying to test your scenario using our quickstart repo but it seems to work just fine. I'm testing with version Firebase Realtime Database 11.9.0 and Unity Editor 2022.3.24f1. That said, could you answer the following:

  1. You mentioned in [3] that "Error is triggered referencing persistent_connection.cc". Are you saying after adding ValueChanged callback, the error is already triggered?
  2. Can you provide a MCVE so that we can check if there's a difference in setup that's causing this issue"

Thanks in advance!

lmt385 commented 1 month ago

Hello, The error triggers upon the callback being registered, yes.

I'll see what I can do in terms of providing a MCVE.

Edit: While digging deeper, it doesn't seem to be triggering upon the listeners being registered, but at a later point related to the initial callbacks when calling GetValueAsync.

The general flow is:

  1. 3 OnValueChanged callbacks assigned, followed by 7 more once those are finished
  2. The ValueChanged callbacks in turn call a method that uses GetValueAsync for a child reference, if the value returned by the callback meets a condition a. So, it goes: ValueChanged Callback associated with reference.Child("attribute") -> Callback checks if condition is met -> Method that calls await reference.Child("setting").GetValueAsync()
  3. On the Mac Editor, GetValueAsync is triggering the persistent_connection.cc error if present in this flow. When commented out, the code executes without issue. GetValueAsync does not cause an error if it is not associated with the callback.