Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity Editor Freezes (Firebase SDK 6.2.2 6.3.0) #445

Closed
yakirbu opened this issue Aug 13, 2019 · 6 comments
Closed

Unity Editor Freezes (Firebase SDK 6.2.2 6.3.0) #445

yakirbu opened this issue Aug 13, 2019 · 6 comments

Comments

@yakirbu
Copy link

yakirbu commented Aug 13, 2019

After upgrading Firebase from 6.1.1 to 6.2.2 (almost all firebase packages),

When calling GetValueAsync() In verbose log mode,
the console prints "[conn_0] websocket message received" endlessly.
Even when we stop the game, the console keeps printing the message.

When we reload the scripts / change the scripts / replay the game or anything that causes Unity to 'Reload Assemblies', Unity freezes (probably because the previous connection is still ongoing, and that might cause the freezes.

@yakirbu yakirbu added the new New issue. label Aug 13, 2019
@radi-cho
Copy link

Hello. I had the same problem (with different versions tho). You can check out the Unity Editor log to see what possibly goes wrong:

macOS		~/Library/Logs/Unity/Editor.log
Windows 	C:\Users\_YOUR-USERNAME_\AppData\Local\Unity\Editor\Editor.log

In my case I solved the issue by re-importing all the Firebase packages I use with consistent versions.

Do not use some packages in 6.1.1 and others in 6.2.2. Clean the project, run the dependency resolver and if needed run Assets -> Reimport All & Restart the editor.

As a workaround: Some of the APIs are working in the editor for easier testing, but some files needed may be corrupted due to the update. If the reimports doesn't help you, just find which boilerplate code causes problems and comment it during the editor work. In my case I had a RemoteConfig initialization, but the Remote Config Editor dll was missing. As temprorary workaround I commented my remote config initialization during work in the editor. Then uncommented it for native Android/iOS builds. Later found out the actual issue and reimported the package which restored the missing dll.

Hopefully this is helpful ;)

@yakirbu
Copy link
Author

yakirbu commented Aug 21, 2019

Hello. I had the same problem (with different versions tho). You can check out the Unity Editor log to see what possibly goes wrong:

macOS		~/Library/Logs/Unity/Editor.log
Windows 	C:\Users\_YOUR-USERNAME_\AppData\Local\Unity\Editor\Editor.log

In my case I solved the issue by re-importing all the Firebase packages I use with consistent versions.

Do not use some packages in 6.1.1 and others in 6.2.2. Clean the project, run the dependency resolver and if needed run Assets -> Reimport All & Restart the editor.

As a workaround: Some of the APIs are working in the editor for easier testing, but some files needed may be corrupted due to the update. If the reimports doesn't help you, just find which boilerplate code causes problems and comment it during the editor work. In my case I had a RemoteConfig initialization, but the Remote Config Editor dll was missing. As temprorary workaround I commented my remote config initialization during work in the editor. Then uncommented it for native Android/iOS builds. Later found out the actual issue and reimported the package which restored the missing dll.

Hopefully this is helpful ;)

Unfortunately, I'm not using any packages from 6.1.1 (removed all completely and validated)
Also, reloading all assets didn't help.
I'm not missing any dll, after using debugger, I noticed that my it stops when it reaches the point where I call 'GetValueAsync()' to retrieve data from Realtime-Database.
As I mentioned earlier, when using verbose log mode, it keeps printing "[conn_0] websocket message received" endlessly even after stopping the game.

@radi-cho
Copy link

@yakirbu can you post the code where you call GetValueAsync?

@yakirbu
Copy link
Author

yakirbu commented Aug 21, 2019

@yakirbu can you post the code where you call GetValueAsync?

public async Task<T> GetData<T>(DatabaseReference dbRef, string child = null, string orderByChild = null, string equalTo = null)
    {
        Query tempRef = dbRef;
        if (!string.IsNullOrEmpty(child))
            tempRef = tempRef.Reference.Child(child);
        if (!string.IsNullOrEmpty(orderByChild))
            tempRef = tempRef.OrderByChild(orderByChild);
        if (!string.IsNullOrEmpty(equalTo))
            tempRef = tempRef.EqualTo(equalTo);
        var tempTask = tempRef.GetValueAsync();
        var snap = await tempTask;
        if (snap != null && snap.ChildrenCount > 0)
        {
            T val = default;
            foreach (var snapChild in snap.Children)
            {
                var json = snapChild.GetRawJsonValue();
                if(json[0] != '{')
                {
                    json = "{\""   snapChild.Key   "\":"   json   "}";
                }
                val = GetObjFromJSON<T>(json);
                var keyField = val.GetType().GetField("key");
                if (keyField != null)
                    keyField.SetValue(val, snapChild.Key);             
            }
            return val;
        }
        Debug.Log("error - no children");
        return default;       
    }

It stops at the line:
var snap = await tempTask;

If I downgrade to 6.1.1, everything works as usual.

@yakirbu yakirbu changed the title Unity Editor Freezes (Firebase SDK 6.2.2) Unity Editor Freezes (Firebase SDK 6.2.2 6.3.0) Aug 22, 2019
@patm1987
Copy link

Thanks for that sample @yakirbu.

Can you give us some information on your current setup?
Unity version.
Unity Editor platform (mac/win/linux).
Unity target (android/ios/other). I know that this is an editor issue, but there could still could be some configuration changes according to your target platform.

Exceptions are used to indicate errors in data retrieval. Can you let us know if you see any of those?
You may see in our examples/docs that we handle these with task.IsFaulted, but an exception will be raised instead that you should try to capture with a try/catch block if you don't check this field.

If you don't mind, it would help us a ton if you could get us instructions for how to reproduce this issue in the test app.

Another thing that would be super helpful if you could try is trying to take more direct control of the FirebaseDatabase.DefaultInstance. Internal to Firebase, this is currently a weak reference (although it should stay around for the duration of your query). If you have any sort of manager class (say, where you call CheckAndFixDependenciesAsync), it would be really helpful to know if keeping a reference there makes your issue go away.

Similarly, if you're already keeping a reference to FirebaseDatabase.DefaultInstance around, try setting it to null in OnDestroy. Ex (I'm writing this inline, so there may be a typo or two):

public class DatabaseManager: MonoBehaviour {
    FirebaseDatabase _db;
    void Start() {
        _db = FirebaseDatabase.DefaultInstance;
    }

    void OnDestroy() {
        _db = null;
    }
}

This changes behavior a little because in the UnityEditor, all the native plugins are kept around between play cycles (when you stop playing the game, the Database stays in its current state). Clearing all references to the database might clear it out.

Now, this might not work since you have an active query going on (it seem). What you can also do is try putting in a FirebaseDatabase.DefaultInstance.Dispose(); in a manager class (say in an OnApplicationQuit() callback). This should not be necessary, but let us know if it does fix your issue!

I look forward to your response!
--Patrick

@yakirbu
Copy link
Author

yakirbu commented Sep 1, 2019

Hi,
So I'm glad to say that this issue is now resolved.
I've managed to fix it by doing a thorough clean-up to my project (Including Library folder and unused plugins).
Can't really say what caused the issue, but I'm glad it is no longer happening.

@yakirbu yakirbu closed this as completed Sep 1, 2019
@firebase firebase locked and limited conversation to collaborators Oct 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants