Open megavoid opened 2 years ago
HI @megavoid,
Thanks for reporting this issue. Unfortunately, we couldn't test using the .exe
file you provided due to security reasons. It would be helpful if you could share the Unity project so that we can identify what's causing this behavior.
Additionally, could you share the error message when using the quickstart? This may be caused by a missing dependency in your implementation.
Hi @paulinon,
Thanks for responding. The Unity project is not public and cannot be shared. In the meantime I was able to fix the dependency issues with quickstart and am currently trying to reproduce the issue in that barebones project.
After 2 more days of research there is some good news and some bad news. Bad news first: I have not been able to replicate the issue using the auth and database quickstart templates separately. My guess is that the issue is caused by the interplay of both the auth and database modules. I tried using the original database access code from our App in the database quickstart project without auth and it did not crash.
Good news is that I have found a workaround: After login our App makes three calls to the database module using GetValueAsync() on different RootReference children to load some settings. Once these have been completed I now call DatabaseReference.GoOffline();. This simple call prevents the App from crashing after the one hour delay.
I have also confirmed that the crash is being caused only with the database module being present. In one test I have simply ripped out all traces of the database module and replaced the required data with local constants. Our Firebase auth code was left untouched in this test. That worked perfectly fine without crashes.
I hope this in enough information to get a grip on the issue.
Hi @megavoid,
Thanks for the update. I've consulted this with the team, and it turns out that the behavior you're facing is actually a bug. The crash that occurs after an hour may have something to do with Firebase ID tokens lasting that long.
That said, we'll be working on this. For now, could you confirm if you've set up a custom auth listener in your implementation?
Hi @paulinon,
This is our Auth program flow, we are using a standard Unity Monobehaviour class:
private void Start()
{
Auth = null;
User = null;
TaskScheduler taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
{
dependencyStatus = task.Result;
if (dependencyStatus == DependencyStatus.Available)
{
InitializeFirebase();
}
else
{
Debug.LogError("Firebase Error, could not resolve Dependencies: " + dependencyStatus);
}
}, taskScheduler);
}
private void InitializeFirebase()
{
Auth = FirebaseAuth.DefaultInstance;
DatabaseReference = FirebaseDatabase.DefaultInstance.RootReference;
FirebaseDatabase.DefaultInstance.SetPersistenceEnabled(false);
OnFirebaseReady?.Invoke();
}
The OnFirebaseReady event calls this function:
private void FirebaseReady()
{
TryResumeSession();
OnFirebaseReady -= FirebaseReady;
}
private void TryResumeSession()
{
if (Auth.CurrentUser != null)
{
User = Auth.CurrentUser;
if (User.IsEmailVerified)
{
OnUserSignedIn?.Invoke();
}
else
{
// Reset values and display login screen
Logout();
}
}
}
[REQUIRED] Please fill in the following fields:
[REQUIRED] Please describe the issue here:
On Windows our software crashes exactly 1 hour after signing in to Firebase. This happens about 90% of the time on several test machines with the compiled App (both IL2CPP and Mono) and both with username/password login and resume session by token. Running content / scenes do not matter, it even crashes only being idle in main menu.
It also crashes the Unity editor, though it seems to happen less often than the compiled App, about 70% of the time.
The App runs totally fine being signed out (login screen at start) and also does not crash when there is no internet connection available (cable pulled, wifi deactivated) at the usual crash point after 1 hour runtime.
The Mac version is completely stable.
What I did try
As the crash timing is so exact, my first thought was that it is related to the ID token expiring. Thus I added code to manually refresh the ID token every 15 minutes. This did not fix the issue. As the only other thing we do on Firebase right now is getting some data from the Realtime Database after login we also tried the workaround from this issue -> https://github.com/firebase/quickstart-unity/issues/1284 disabling Persistence. This also did not fix our crashes.
Steps to reproduce:
Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? No, quickstarts has compiler errors in Unity 2021.3
What's the issue repro rate? (eg 100%, 1/5 etc) 90% compiled, 70% editor
What happened? How can we make the problem occur? Download our software from https://get.infinite-realms.de/2022/Setup_IR-2022.0.5.exe - install - sign up & in - wait 1 hour
Relevant Code:
Stack Trace v8.8.0:
Weirdly FirebaseAnalytics shows up in the trace, although the module is not installed. We did try to install FirebaseAnalytics SDK afterwards because we thought maybe a call to the absent module caused the crash. This also did not fix the issue.
Stack Trace v10.1.0
Login routines:
Realtime Database call example. We only do these after login. When offline and signed in via token the App loads settings from cache file instead of database:
Attempt to fix the crash by manually refreshing ID token every 15 minutes: