Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ANR] Firebase Cloud Messaging ANR - Native method - android.os.MessageQueue.nativePollOnce #1208

Open
MDThreye opened this issue Mar 7, 2025 · 3 comments
Labels

Comments

@MDThreye
Copy link

MDThreye commented Mar 7, 2025

Description

We are experiencing an Application Not Responding (ANR) issue in our Android application, with logs indicating prolonged blocking in the native call to android.os.MessageQueue.nativePollOnce. Analysis of the stack trace from Firebase Crashlytics shows that several threads—including the main thread, Unity-related threads, and various background service threads—are consistently entering native wait states.

Key Details from the Log File:

• Main Thread Blockage:
The primary stack trace indicates that the main thread is halted within android.os.MessageQueue.nativePollOnce, cascading into calls such as Looper.loop and ActivityThread.main. This blockage directly contributes to UI freezes.

• Unity Integration Impact:
Logs reveal that Unity-specific threads, such as “UnityMain,” are similarly affected. These threads show multiple wait states in native calls, suggesting that background processing related to Unity might be intermingling with the issue.

• Multiple Background Threads Affected:
Other threads—including those associated with system services and background tasks (e.g., “InsetsAnimations”, “AssetPackService”, “ConnectivityThread”, “GoogleApiHandler”)—are seen waiting on native polling or further operations. This systemic blockage hints at an underlying issue in the message queue handling.

• Suspected Firebase Cloud Messaging Cause:
Further investigation into the context of the logs has led us to suspect that Firebase Cloud Messaging (FCM) is triggering this ANR. It appears that when FCM processes and delivers messages, it may be causing delays or interfering with the normal operation of the message queue. This interference could be compounding the thread blockage observed across both UI and background processing threads.

Impact:

User Experience: The ANR results in significant UI freezes, negatively affecting overall user engagement.
System Stability: The involvement of multiple threads—including those related to Unity and background services—indicates that FCM-related processing might be creating a broader contention issue within our application's message handling system.
Request for Investigation:

Examine recent changes in our Firebase Cloud Messaging integration to determine if they might be affecting message queue processing.
Investigate potential thread contention or synchronization issues triggered by FCM callbacks that lead to prolonged blocking in nativePollOnce.
Explore possible mitigations or workarounds to prevent FCM from causing message queue congestion, particularly in environments that combine Unity and native Android components.

ANR Log.txt

Reproducing the issue

initialize firebase and Messaging at Init ANR happens

here is code snippet of initialization
`
private Firebase.FirebaseApp appFirebase = null;

    Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
    {
        var dependencyStatus = task.Result;
        if (dependencyStatus == Firebase.DependencyStatus.Available)
        {
            appFirebase = Firebase.FirebaseApp.DefaultInstance;
            Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
            Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
        }
        else
        {
            Debug.Log(System.String.Format(
              "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
        }
    });
    
private void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token)
{
    Debug.Log("FCM Token : " + token.Token);
}
private void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e)
{     
}

`

Firebase Unity SDK Version

12.6.0

Unity editor version

2022.3.55f1

Installation Method

Unity Package Manager

Problematic Firebase Component(s)

Messaging, In-App Messaging

Other Firebase Component(s) in use

Analytics, Crashlytics, Messaging, In-App Messaging

Additional SDKs you are using

ByteBrew SDK = 0.1.9,
Google AdMob = 9.2.0,
Playfab = 2.209.250228
Playmaker = 1.9.4.f

Targeted Platform(s)

Android

Unity editor platform

Windows, Mac

Scripting Runtime

IL2CPP

Release Distribution Type

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

Relevant Log Output

main (native):tid=1 systid=12579 
#00 pc 0x9ca68 libc.so (__epoll_pwait + 8)
#01 pc 0x19d88 libutils.so (android::Looper::pollInner(int) + 184)
#02 pc 0x19c68 libutils.so (android::Looper::pollOnce(int, int*, int*, void**) + 112)
#03 pc 0x11232c libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce(_JNIEnv*, _jobject*, long, int) + 44)
       at android.os.MessageQueue.nativePollOnce(Native method)
       at android.os.MessageQueue.next(MessageQueue.java:335)
       at android.os.Looper.loop(Looper.java:183)
       at android.app.ActivityThread.main(ActivityThread.java:7785)
       at java.lang.reflect.Method.invoke(Native method)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)

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!
@MDThreye MDThreye added new New issue. type: bug labels Mar 7, 2025
@google-oss-bot
Copy link

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

@argzdev
Copy link

argzdev commented Mar 14, 2025

Hey @MDThreye, thanks for reaching out. Could you answer a few questions below?

  1. Is this issue reproducible only on Android 14 devices or lower? This looks like a similar issue that's been happening on Android 15 devices.
  2. Is this issue always reproducible? Or is there particular steps to reproduce this behavior consistent?

@argzdev argzdev added the needs-info Need information for the developer label Mar 14, 2025
@MDThreye
Copy link
Author

@argzdev Hello, thanks for reaching out!

  1. Yes, this issue is reproducible on Android 14 devices or lower, primarily on devices running Android 11. We have not tested it on Android 15 devices.

  2. Yes, this issue is consistently reproducible, and no specific steps are required to observe this behavior.

Let me know if you need any further details!

Hey @MDThreye, thanks for reaching out. Could you answer a few questions below?

  1. Is this issue reproducible only on Android 14 devices or lower? This looks like a similar issue that's been happening on Android 15 devices.
  2. Is this issue always reproducible? Or is there particular steps to reproduce this behavior consistent?

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants