firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
234 stars 38 forks source link

[Bug] SIGSEGV in firebase::analytics::SetConsent #1104

Open gamma-omg opened 3 months ago

gamma-omg commented 3 months ago

Description

We are experiencing a significant number of crashes related to Firebase Analytics when calling the FirebaseAnalytics.SetConsent method, as reported by Google Play Console. Below are the details from the crash logs:

SIGSEGV
[libFirebaseCppApp-12_1_0.so] firebase::analytics::SetConsent(std::__ndk1::map<firebase::analytics::ConsentType, firebase::analytics::ConsentStatus, std::__ndk1::less<firebase::analytics::ConsentType>, std::__ndk1::allocator<std::__ndk1::pair<firebase::analytics::ConsentType const, firebase::analytics::ConsentStatus> > > const&)

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 1242 >>> <package_name> <<<

backtrace:
  #00  pc 0x00000000002473cc  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libFirebaseCppApp-12_1_0.so (firebase::analytics::SetConsent(std::__ndk1::map<firebase::analytics::ConsentType, firebase::analytics::ConsentStatus, std::__ndk1::less<firebase::analytics::ConsentType>, std::__ndk1::allocator<std::__ndk1::pair<firebase::analytics::ConsentType const, firebase::analytics::ConsentStatus> > > const&)+724)
  #01  pc 0x0000000004133e9c  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (FirebaseAnalytics_SetConsentInternal_m4D1F62C08DB3407F48F553A53B497E02802F1774+9116) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #02  pc 0x00000000033303f0  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (FirebaseAnalyticsClient_UpdateConsendMode_mBA6BB2E5DD3C3EBD8BFF6CC204A7C4286FBBB08C+12920) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #03  pc 0x000000000332ffe0  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (FirebaseAnalyticsClient_Activate_mA962DF970237F3C534F2F374B29C5DB893D821D7+12579) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #04  pc 0x0000000003abb6c4  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (GameLauncher_SetupAccountId_mFCF665B3A4E2806021104A3A27DD8282C3AD6D82+21) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #05  pc 0x0000000003abe468  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (U3CAuthAsyncU3Ed__51_MoveNext_mF95EA70772717D06355601559698723F0E39B12E+20311) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #06  pc 0x00000000062eb828  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (ExecutionContext_RunInternal_mC37E85D6FC972DF219A00FE1EE34329D1D63CC94+31206) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #07  pc 0x000000000618bcb8  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (MoveNextRunner_Run_m86395F123FB453F2B5FF89CE1E98532F7426F9DE+26758) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #08  pc 0x00000000063028ac  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (AwaitTaskContinuation_RunCallback_m37C4A227BA403A3D28CC94369A8770F1C16AE4E5+32915) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #09  pc 0x00000000062fbfdc  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (Task_FinishContinuations_m21B540B556CDABD76F5985DF83079F7F30C78174+48) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #10  pc 0x0000000004eb0a9c  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (Task_1_TrySetResult_m2EE766FD3F76F4824990F4A93ED1F7253ECE014C_gshared+6264) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #11  pc 0x0000000005567038  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (AsyncTaskMethodBuilder_1_SetResult_m0D83195F995F9825D7A6DCDC3835D6917C43B5A6_gshared+5450) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #12  pc 0x0000000003468a8c  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (U3CGetAuthAsyncU3Ed__16_MoveNext_m98E9A5449C8FD4532ABA9E535416524944ED949A+12381) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #13  pc 0x00000000062eb828  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (ExecutionContext_RunInternal_mC37E85D6FC972DF219A00FE1EE34329D1D63CC94+31206) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #14  pc 0x000000000618bcb8  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (MoveNextRunner_Run_m86395F123FB453F2B5FF89CE1E98532F7426F9DE+26758) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #15  pc 0x00000000063028ac  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (AwaitTaskContinuation_RunCallback_m37C4A227BA403A3D28CC94369A8770F1C16AE4E5+32915) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #16  pc 0x00000000062fbfdc  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (Task_FinishContinuations_m21B540B556CDABD76F5985DF83079F7F30C78174+48) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #17  pc 0x0000000004eb0a9c  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (Task_1_TrySetResult_m2EE766FD3F76F4824990F4A93ED1F7253ECE014C_gshared+6264) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #18  pc 0x0000000005567038  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (AsyncTaskMethodBuilder_1_SetResult_m0D83195F995F9825D7A6DCDC3835D6917C43B5A6_gshared+5450) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #19  pc 0x0000000005b967f4  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (U3CSendU3Ed__9_MoveNext_m9B46F35855C66941A240BD67DA13E6E1A40EDCBA_gshared+3381) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #20  pc 0x00000000062eb828  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (ExecutionContext_RunInternal_mC37E85D6FC972DF219A00FE1EE34329D1D63CC94+31206) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #21  pc 0x000000000618bcb8  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (MoveNextRunner_Run_m86395F123FB453F2B5FF89CE1E98532F7426F9DE+26758) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #22  pc 0x00000000063028ac  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (AwaitTaskContinuation_RunCallback_m37C4A227BA403A3D28CC94369A8770F1C16AE4E5+32915) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #23  pc 0x00000000062fbfdc  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (Task_FinishContinuations_m21B540B556CDABD76F5985DF83079F7F30C78174+48) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #24  pc 0x0000000004eb0a9c  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (Task_1_TrySetResult_m2EE766FD3F76F4824990F4A93ED1F7253ECE014C_gshared+6264) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #25  pc 0x0000000005567038  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (AsyncTaskMethodBuilder_1_SetResult_m0D83195F995F9825D7A6DCDC3835D6917C43B5A6_gshared+5450) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #26  pc 0x00000000030d0750  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (U3CHandleHttpExceptionsU3Ed__8_MoveNext_mDE9F9E6CCFB511C514F36A7649CD119365E5E415+2294) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #27  pc 0x00000000062eb828  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (ExecutionContext_RunInternal_mC37E85D6FC972DF219A00FE1EE34329D1D63CC94+31206) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #28  pc 0x000000000618bcb8  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (MoveNextRunner_Run_m86395F123FB453F2B5FF89CE1E98532F7426F9DE+26758) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #29  pc 0x0000000006a7f9f8  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (WorkRequest_Invoke_mBFEC6A3799BAFDE7ED840A0523D3D56160C03921+32688) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #30  pc 0x0000000006a7f940  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (UnitySynchronizationContext_Exec_m7E6352CBA70E4AB14F7D50A919C3F8C22F2E977A+26555) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #31  pc 0x0000000002e09cf0  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**)+608) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #32  pc 0x0000000002e09c30  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libil2cpp.so (il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**)+594) (BuildId: 7385ba0de9d342695970145c145309171ea19be8)
  #33  pc 0x00000000009423cc  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libunity.so (scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool)) (BuildId: 9817f552ebb05d89850eab0b8076eecfde7aded0)
  #34  pc 0x0000000000950710  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libunity.so (ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool)) (BuildId: 9817f552ebb05d89850eab0b8076eecfde7aded0)
  #35  pc 0x00000000009fe758  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libunity.so (Scripting::UnityEngine::UnitySynchronizationContextProxy::ExecuteTasks(ScriptingExceptionPtr*)) (BuildId: 9817f552ebb05d89850eab0b8076eecfde7aded0)
  #36  pc 0x000000000082c308  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libunity.so (ExecutePlayerLoop(NativePlayerLoopSystem*)) (BuildId: 9817f552ebb05d89850eab0b8076eecfde7aded0)
  #37  pc 0x000000000082c348  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libunity.so (ExecutePlayerLoop(NativePlayerLoopSystem*)) (BuildId: 9817f552ebb05d89850eab0b8076eecfde7aded0)
  #38  pc 0x000000000082c5dc  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libunity.so (PlayerLoop()) (BuildId: 9817f552ebb05d89850eab0b8076eecfde7aded0)
  #39  pc 0x00000000009cac24  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libunity.so (UnityPlayerLoop()) (BuildId: 9817f552ebb05d89850eab0b8076eecfde7aded0)
  #40  pc 0x00000000009e3fc8  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/lib/arm64/libunity.so (nativeRender(_JNIEnv*, _jobject*)) (BuildId: 9817f552ebb05d89850eab0b8076eecfde7aded0)
  #41  pc 0x000000000010b644  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/oat/arm64/base.odex (art_jni_trampoline+116)
  #42  pc 0x000000000026fc24  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/oat/arm64/base.odex (com.unity3d.player.UnityPlayer$F$a.handleMessage+948)
  #43  pc 0x00000000009317ec  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.Handler.dispatchMessage+124)
  #44  pc 0x0000000000934a54  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.Looper.loopOnce+980)
  #45  pc 0x0000000000934604  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.Looper.loop+244)
  #46  pc 0x00000000002706fc  /data/app/~~vZeLbL9za4MbncjLqYLBDA==/<package_name>-4uMaeLCtEiN0lrHT3PSR1Q==/oat/arm64/base.odex (com.unity3d.player.UnityPlayer$F.run+652)
  #47  pc 0x000000000033a7a4  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+612)
  #48  pc 0x000000000023a01c  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+144)
  #49  pc 0x0000000000539054  /apex/com.android.art/lib64/libart.so (art::Thread::CreateCallback(void*)+1600)
  #50  pc 0x0000000000538a04  /apex/com.android.art/lib64/libart.so (art::Thread::CreateCallbackWithUffdGc(void*)+8)
  #51  pc 0x000000000006efbc  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+204)
  #52  pc 0x0000000000060d60  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64)

Even with invalid parameters passed to FirebaseAnalytics.SetConsent, we expect this method to handle errors gracefully by either throwing an exception or logging the error. However, it currently causes the application to crash.

Could you please investigate this issue? Ideally, the method should fail gracefully without crashing the app.

Reproducing the issue

We were unable to reproduce the issue locally and have only observed it through crash logs provided by Google Play Console. According to these reports:

Firebase Unity SDK Version

12.1.0

Unity editor version

2022.3.41f1

Installation Method

.unitypackage

Problematic Firebase Component(s)

Analytics

Other Firebase Component(s) in use

Analytics, Crashlytics, Messaging, Remote Config

Additional SDKs you are using

Targeted Platform(s)

Android

Unity editor platform

Mac, Windows

Scripting Runtime

IL2CPP

Release Distribution Type

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

Relevant Log Output

No response

If using CocoaPods for Apple platforms, the project's Podfile.lock

No response

google-oss-bot commented 3 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

argzdev commented 3 months ago

Hi @gamma-omg, thanks for reaching out. Were you using a previous version of Firebase Analytics before encountering this issue? If so, could you share which version was it? I'm wondering if this was caused by a recent update in our native Firebase Android SDK which was added during the release of version 12.1.0 of Firebase Unity SDK.

gamma-omg commented 3 months ago

Hi @argzdev, thanks for your reply. We were using Firebase 11.9.0 when we first encountered this issue. We had been using this version for quite some time without any problems. However, when we started using the FirebaseAnalytics.SetConsent API, it began to crash. We tried updating to 12.1.0, but the problem persisted.

argzdev commented 3 months ago

Thanks for the extra details, @gamma-omg. Any chance you could share some sample code snippets of your usage with FirebaseAnalytics.SetConsent so we can narrow down our investigation? Thanks!

gamma-omg commented 2 months ago

@argzdev Hi! Unfortunately, I can't provide you with detailed source code, but here's what we basically do:

Before using any Firebase APIs, we ensure that Firebase is fully initialized by calling our initialization method, which caches the initialization task to prevent redundant calls:

await FirebaseService.Require();

The FirebaseService.Require method works as follows:

public static async Task<bool> Require()
{
    if (_initTask != null)
    {
        return await _initTask == DependencyStatus.Available;
    }

    _initTask = FirebaseApp.CheckAndFixDependenciesAsync();
    var status = await _initTask;

    if (status == DependencyStatus.Available)
    {
        FirebaseApp _ = FirebaseApp.DefaultInstance;
        return true;
    }
    return false;
}

Once Firebase is initialized, we set the user's consent preferences using FirebaseAnalytics.SetConsent. The consent statuses are determined using Google's User Messaging Platform (UMP):

var consentMap = new Dictionary<ConsentType, ConsentStatus>
{
    { ConsentType.AdStorage, GetConsentStatus(ConsentModeService.Purpose.Purpose01) },
    { ConsentType.AnalyticsStorage, GetConsentStatus(ConsentModeService.Purpose.Purpose01) },
    { ConsentType.AdUserData, GetConsentStatus(ConsentModeService.Purpose.Purpose01, ConsentModeService.Purpose.Purpose07) },
    { ConsentType.AdPersonalization, GetConsentStatus(ConsentModeService.Purpose.Purpose03, ConsentModeService.Purpose.Purpose04) }
};

FirebaseAnalytics.SetConsent(consentMap);

If you need any additional information, please let me know. I'll try to help you as much as I can.

stanislavsmagin commented 1 month ago

We have the same problem. Any updates?

mhctseu commented 14 hours ago

Any updates on this issue?