[Bug] Persistent connection error thrown when using Unity 2022 on Mac
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
- DatabaseReference is obtained for a particular node in the Firebase Realtime Database
- A ValueChanged callback is added to the DatabaseReference object
- Error is triggered referencing
persistent_connection.cc - 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
👀 Replace this line with the contents of your Podfile.lock!
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
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:
- You mentioned in [3] that "Error is triggered referencing
persistent_connection.cc". Are you saying after addingValueChangedcallback, the error is already triggered? - 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!
~~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:
- 3
OnValueChangedcallbacks assigned, followed by 7 more once those are finished - The
ValueChangedcallbacks in turn call a method that usesGetValueAsyncfor a child reference, if the value returned by the callback meets a condition a. So, it goes: ValueChanged Callback associated withreference.Child("attribute")-> Callback checks if condition is met -> Method that callsawait reference.Child("setting").GetValueAsync() - On the Mac Editor,
GetValueAsyncis triggering thepersistent_connection.ccerror if present in this flow. When commented out, the code executes without issue.GetValueAsyncdoes not cause an error if it is not associated with the callback.
Similar problem seen on Editor on Mac as well : If I do this subscription: reference.Child(CATEGORY_DATA_KEY).Child(userId).Child(SUBCATEGORY_DATA_KEY).ValueChanged += OnDataChanged;
and then later on do : var LoadTask = reference.Child(CATEGORY_DATA_KEY).Child(userId).GetValueAsync();
it will trigger the error :
/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)
firebase sdk : 11.9.0 unity : 2021.3.22f1