[Bug] Unity App freezes for several seconds to minutes when an exception with a large stacktrace occurs with Crashlytics running
[REQUIRED] Please fill in the following fields:
- Unity editor version: 2021.3.21f1
- Firebase Unity SDK version: 11.4.0
- Source you installed the SDK: .unitypackage
- Problematic Firebase Component: Crashlytics
- Other Firebase Components in use: Analytics
- Additional SDKs you are using: None
- Platform you are using the Unity editor on: Windows
- Platform you are targeting: iOS, Android
- Scripting Runtime: il2cpp
- Pre-built SDK from the website
[REQUIRED] Please describe the issue here:
I would like to re-open issue #563. We appear to be encountering the issue described there, which appears to have been closed without any resolution. As described in that ticket:
Crashlytics increases the time a Unity app freezes when handling an uncaught exception by several orders of magnitude.
I could retype and redescribe everything in that ticket but it feels a bit wasteful to do so.
I cloned the repo mentioned in the original ticket and updated Firebase to v11.4.0. I also modified the scene and added a button that does a try/catch to see how handled exceptions that still log the error behaves. The only additional information I can add is that even the TryCatch causes the freeze even though I am not explicitly logging it to Crashlytics. It does, however, only behave this way when Crashlytics is initialized which would seem to indicate that Crashlytics is still the problem.
Steps to reproduce:
The steps described in the original ticket still apply:
- Open the crashlytics-issue-repro project in Unity 2021.3.21f1
- Import your own
google-services.json - Ensure scripting backend is set to IL2CPP
- Build and run on any Android phone. The issue is much more visible on slightly older phones.
- After the app starts, press the "Freeze for 3 Seconds" button as a calibration test. This simply invokes
Thread.Sleep(3000), so the resulting text should show a freeze of around 3 seconds. - Press the three "Throw" buttons in sequence. "Throw (Simple Stack)" and "Throw (Many Threads)" should be very fast, while "Throw (Async Stack)" could lead to a short freeze.
- Press the "Initialize Firebase" button. Crashlytics is now running.
- Press the three "Throw" buttons in sequence. "Throw (Simple Stack)" and "Throw (Many Threads)" should now take several seconds (depending on device), while "Throw (Async Stack)" and "Throw (Async Stack TryCatch)" should lead to a very long freeze (almost 30 minutes on the Huawei device).
Downloadable Repro Project: https://github.com/FodderMK/crashlytics-issue-repro
Hi @FodderMK,
Apologies for the radio silence here. Version 11.5.0 of the SDK has been released recently. Could you try it out and see if you're facing a similar behavior?
@paulinon I have updated the project to v11.5.0 and am still seeing the same issue.
Reported here as well: https://github.com/firebase/firebase-unity-sdk/issues/563
@paulinon Is there anything else I can try to provide to help with this issue?
@FodderMK, we had a bug about this in the past: https://github.com/firebase/firebase-unity-sdk/issues/563
We found this is a limitation in how Unity handles unhandled exceptions. There's advice in the comment on how to work around it: https://github.com/firebase/firebase-unity-sdk/issues/563#issuecomment-1505470880
@samedson Thanks for the response! I am aware of issue #563 and even reference it in my opening sentence for describing the issue:
I would like to re-open issue https://github.com/firebase/firebase-unity-sdk/issues/563.
I tried implementing the fix mentioned in the comment you are referring to and it did not seem to work for me. From my description above:
I also modified the scene and added a button that does a try/catch to see how handled exceptions that still log the error behaves. The only additional information I can add is that even the TryCatch causes the freeze even though I am not explicitly logging it to Crashlytics. It does, however, only behave this way when Crashlytics is initialized which would seem to indicate that Crashlytics is still the problem.
The code in question is in the linked repo starting at FirebaseView.cs:87
The comment references a successful test on iOS. I am testing on Android so that might explain why it is still an issue for me even with that fix in place. Another option could be that my implementation is incorrect. Is it possible for you to take a look at the provided example project to either verify it is an issue or that I am making a mistake?