Quickstart-unity: Opening two unity editor with same firebase project causing unity crash

Created on 12 Jan 2021  ·  4Comments  ·  Source: firebase/quickstart-unity

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2018.4.24f1
  • Firebase Unity SDK version: 6.16
  • Source you installed the SDK: .unitypackage
  • Problematic Firebase Component: Database
  • Other Firebase Components in use: RemoteConfig, FCM,
  • Additional SDKs you are using: Facebook
  • Platform you are using the Unity editor on: Windows
  • Platform you are targeting: desktop
  • Scripting Runtime: Mono

[REQUIRED] Please describe the issue here:

Unity got crashed while using two unity editor logging same firebase project at the same time on single desktop. According to log, it is file access violation due to leveldb creation/removal.
unity_editor_crash.txt

The bug seems related to "persistent storage" which was introduced in 6.16. I am not sure which version of firebase-cpp-sdk is used by firebase-unity. But from firebase-cpp-sdk 6.16, it tries to create db from app_data_path.

https://github.com/firebase/firebase-cpp-sdk/blob/master/database/src/desktop/core/repo.cc#L477

From the crash log, you could find the path is C:\Users\maggie\AppData\Local\/rayark-soe-beta.firebaseio.com.

After that, it tries to initialize levelDbPersistenceStorageEngine and also open DB. However, if the DB:Open fails, it calls assert(false) which caused unity editor crash. After further investigation, it looks like the crash is caused by access violation and maybe triggered by firebase its own due to the log.

ERROR: Failed to initialize persistence storage engine at path C:\Users\victorchang\AppData\Local/rayark-soe-beta-chat.firebaseio.com: IO error: C:\Users\victorchang\AppData\Local/rayark-soe-beta-chat.firebaseio.com/LOCK: 程序無法存取檔案,因為檔案正由另一個程序使用。
ERROR: Could not initialize persistence
Crash!!!
SymInit: Symbol-SearchPath: 'C:/Program Files/Unity/Hub/Editor/2018.4.24f1/Editor/Data/Mono;.;D:\SOE\Client;C:\Program Files\Unity\Hub\Editor\2018.4.24f1\Editor;C:\WINDOWS;C:\WINDOWS\system32;SRVC:\websymbolshttp://msdl.microsoft.com/download/symbols;', symOptions: 534, UserName: 'victorchang'
OS-Version: 10.0.0
C:\Program Files\Unity\Hub\Editor\2018.4.24f1\Editor\Unity.exe:Unity.exe (0000000140000000), size: 79466496 (result: 0), SymType: '-deferred-', PDB: '', fileVersion: 2018.4.24.29073
C:\WINDOWS\SYSTEM32\ntdll.dll:ntdll.dll (00007FFCDD8E0000), size: 2031616 (result: 0), SymType: '-deferred-', PDB: '', fileVersion: 10.0.18362.1171
C:\WINDOWS\System32\KERNEL32.DLL:KERNEL32.DLL (00007FFCDCA50000), size: 729088 (result: 0), SymType: '-deferred-', PDB: '', fileVersion: 10.0.18362.1110
BackendService: OnLogin: End
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(String, Object)
Rayark.SoulOfEden.UnityLogger:Rayark.SoulOfEden.ILogger.Log(String, Object) (at Assets\Scripts\Rayark\SoulOfEden\UnityLogger.cs:31)
Rayark.SoulOfEden.Backend.RayarkNet.<>c__DisplayClass57_01:<_TransformServiceErrors>b__1() (at Assets\Scripts\Rayark\SoulOfEden\Backend\RayarkNet\AllRayarkBackendService.cs:291) Rayark.<>c__DisplayClass2_01:b__0(None) (at Assets\Rayark\Scripts\Utility.cs:1094)
Rayark.Mast.d__9:MoveNext()
Rayark.Mast.Coroutine:_Resume()
Rayark.Mast.Coroutine:Resume(Single)
Rayark.Mast.Executor:Resume(Single)
Rayark.Mast.d__1:MoveNext()
Rayark.Mast.Coroutine:_Resume()
Rayark.Mast.Coroutine:Resume(Single)
Rayark.Mast.Executor:Resume(Single)
Rayark.SoulOfEden.Scenes.<_Loop>d__36:MoveNext() (at Assets\Scripts\Rayark\SoulOfEden\Scenes\SceneManager.cs:338)
Rayark.Mast.Coroutine:_Resume()
Rayark.Mast.Coroutine:Resume(Single)
Rayark.Mast.Executor:Resume(Single)
Rayark.Mast.d__12:MoveNext()
Rayark.Mast.Coroutine:_Resume()
Rayark.Mast.Coroutine:Resume(Single)
Rayark.SoulOfEden.ApplicationContextWrapper:Update() (at Assets\Scripts\Rayark\SoulOfEden\ApplicationContextWrapper.cs:232)

https://github.com/firebase/firebase-cpp-sdk/blob/master/database/src/desktop/persistence/level_db_persistence_storage_engine.cc#L307

In my scenario, I have opened two unity editors with the same firebase project id. Hence, Db:Open would always return failure due to DB has already been created by the former editor. Then, assert(false) would be called causing unity crash.

Steps to reproduce:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)?
No

What's the issue repro rate?
100%

What happened?
Unity crash

How can we make the problem occur?

  1. Prepare two unity editors on same desktop
  2. Prepare two firebase account with same project id
  3. Set Persistence Enable true (default is true)
  4. Get into play mode with both editors and login firebase. Then unity crashes.
database firestore bug

Most helpful comment

This seems to be a bug in how persistent feature is implemented on desktop.

On Windows, persistent data is stored at <LocalAppDataFolder>/<package_name>/<database_domain>. See this code.

The problem is, when there are two Unity editor instances, they will attempt to write to the same location and cause the assert.

This is definitely an unique issue for desktop, but not for Android or iOS, since they only has one instance at a time.

I'll contact the team about this issue. At the meantime, I would recommend you to disable persistence in editor. Something like

#if UNITY_EDITOR
  Firebase.FirebaseDatabase.DefaultInstance.SetPersistenceEnabled(false);
#endif

All 4 comments

Update:

I have upgraded firebase-unity to 7.0.2 but with no luck. Here are the logs generated with dump. I do have a dump file but there is no way for me to upload it.

error.log

Editor.log

vinddbg_dump_analytic.txt

This seems to be a bug in how persistent feature is implemented on desktop.

On Windows, persistent data is stored at <LocalAppDataFolder>/<package_name>/<database_domain>. See this code.

The problem is, when there are two Unity editor instances, they will attempt to write to the same location and cause the assert.

This is definitely an unique issue for desktop, but not for Android or iOS, since they only has one instance at a time.

I'll contact the team about this issue. At the meantime, I would recommend you to disable persistence in editor. Something like

#if UNITY_EDITOR
  Firebase.FirebaseDatabase.DefaultInstance.SetPersistenceEnabled(false);
#endif

@chkuang-g thank you for your walkaround!

For Firestore this would be:
FirebaseFirestore.DefaultInstance.Settings.PersistenceEnabled = false;

Seems like Firestore has the same issue as well

Was this page helpful?
0 / 5 - 0 ratings