[Bug] Editor crashes in AppUtilPINVOKE.PollCallbacks after domain reload when a custom App Check provider factory is registered

Aperta
#1,530 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp, unity
Ambito
desktop, security

Direzione di ricerca

Start with app_check/src/swig/app_check.i and app_check/src/FirebaseAppCheck.cs, tracing SetAppCheckProviderFactory through AppCheckUtil.SetGetTokenCallback and the callbacks invoked by PollCallbacks. Read app/platform/Unity/FirebaseEditorDispatcher.cs around OnCleanupEvent to compare existing reload cleanup. Done means reproducing or isolating the stale-callback crash and ensuring callbacks are safely reset across domain reload or editor shutdown.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

api: appcheck desktop production type: bug
Description

The Unity Editor intermittently crashes with a native access violation (DEP violation)
inside Firebase.AppUtilPINVOKE.PollCallbacks on the first Play after a domain reload
(script recompilation or asset import).

Our project has Enter Play Mode Options enabled with domain reload disabled
(EnterPlayModeOptions.DisableDomainReload), so a domain reload only happens on
script recompilation or asset import, not on every Play.

We started seeing this after upgrading both the Unity Editor (6000.0.59f2 -> 6000.0.83f1)
and the Firebase Unity SDK (13.9.0 -> 13.16.0) within the same week.
We have not isolated which of the two upgrades triggered it.

Expected: entering Play mode after a domain reload works normally.
Actual: the editor crashes in PollCallbacks.

Frequency observed in our editor logs:

  • First Play right after a domain reload: 22 crashes / 97 Play sessions
  • Play without a preceding domain reload: 0 crashes / 29 Play sessions

Suspected cause:
FirebaseAppCheck.SetAppCheckProviderFactory(factory) registers C# delegates through
AppCheckUtil.SetGetTokenCallback, which stores them in the static native globals
g_get_token_from_csharp / g_get_limited_use_token_from_csharp.
A token request queues CallGetTokenFromCSharp via callback::AddCallback,
which is then executed from PollCallbacks.

On domain reload the old AppDomain and its delegates are unloaded, but nothing resets these
native function pointers. The editor cleanup added in 13.16.0
(FirebaseEditorDispatcher.OnCleanupEvent -> DisposeAllApps() + Terminate()) does not
clear the App Check callbacks either. In our project a sign-in can issue a token request in
the new domain before the factory is registered again, so PollCallbacks appears to invoke
a stale function pointer.

References (v13.16.0):

Workaround:
We added an editor script that clears the callbacks right before the reload:

[InitializeOnLoad]
static class AppCheckReloadGuard
{
    static AppCheckReloadGuard()
    {
        AssemblyReloadEvents.beforeAssemblyReload += () =>
            FirebaseAppCheck.SetAppCheckProviderFactory(null);
    }
}

Because the crash is intermittent, we have not been able to confirm whether this workaround
fully prevents it.

Suggested fix: reset the App Check get-token callbacks (SetGetTokenCallback(null, null))
when the editor reloads the domain or quits, for example from a beforeAssemblyReload /
DomainUnload handler in the App Check module.

Reproducing the issue

These steps are derived from our project and have not been confirmed in a clean project.

  1. Unity 6000.0.83f1, Firebase Unity SDK 13.16.0 (App, App Check, Auth),
    Enter Play Mode Options enabled with domain reload disabled.
  2. Before FirebaseApp initialization, register a custom factory:
class DummyProviderFactory : IAppCheckProviderFactory
{
    public IAppCheckProvider CreateProvider(FirebaseApp app) => new DummyProvider();
}

class DummyProvider : IAppCheckProvider
{
    public Task<AppCheckToken> GetTokenAsync() =>
        Task.FromResult(new AppCheckToken { Token = "dummy", ExpireTime = DateTime.UtcNow.AddHours(1) });
    public Task<AppCheckToken> GetLimitedUseTokenAsync() => GetTokenAsync();
}
  1. Enter Play mode and sign in (e.g. anonymous auth), then exit Play mode.
  2. Edit any script to trigger a domain reload.
  3. Enter Play mode and sign in before calling SetAppCheckProviderFactory again.
  4. The editor intermittently crashes in PollCallbacks (see the frequency above).
Firebase Unity SDK Version

13.16.0

Unity editor version

6000.0.83f1

Installation Method

Unity Package Manager

Problematic Firebase Component(s)

App Check

Other Firebase Component(s) in use

Analytics, Authentication, Firestore, Functions, Installations, Messaging, Remote Config

Additional SDKs you are using

No response

Targeted Platform(s)

Desktop

Unity editor platform

Windows

Scripting Runtime

Mono

Release Distribution Type

Pre-built SDK from https://firebase.google.com/download/unity

Relevant Log Output

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!

Lingua principale
C#
Stelle
325
Fork
62
Merge medio
1g 17h
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di firebase/firebase-unity-sdk

Tutte le issue di firebase/firebase-unity-sdk

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.