flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[firebase_messaing]: android.os.MessageQueue.nativePollOnce (Native method)

Open Cengizhanerturan opened this issue 1 year ago β€’ 38 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues.

Which plugins are affected?

In-App Messaging

Which platforms are affected?

Android

Description

Hi;

When a notification is sent while the application is in the foreground, it crashes with the android.os.MessageQueue.nativePollOnce (Native method) error. There is no issue with the first notification; it arrives promptly. However, subsequent notifications experience delays. After a while, all pending notifications arrive simultaneously, leading to a crash of the application.

Additionally, notifications are sent via "firebase-admin".

This problem has increased a lot in the last 6-7 months and continues to cause a lot of anr. I am submitting the "Logs & Breadcrumbs" and "Stack trace" information I received from Firebase Crashlytics.

Number of anr received in the last 90 days (31K); crashlytics_anr_count

main (native):tid=1 systid=18662 
#00 pc 0x86f8c libc.so (syscall + 28)
#01 pc 0x1b07a4 libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*) + 148)
#02 pc 0x3a544c libart.so (art::JNI<false>::CallObjectMethodV(_JNIEnv*, _jobject*, _jmethodID*, std::__va_list) + 500)
#03 pc 0x4074 libnativehelper.so (_JNIEnv::CallObjectMethod(_jobject*, _jmethodID*, ...) + 124)
#04 pc 0xed358 libandroid_runtime.so (android::NativeDisplayEventReceiver::dispatchVsync(long, unsigned long, unsigned int) + 48)
#05 pc 0x93c28 libgui.so (android::DisplayEventDispatcher::handleEvent(int, int, void*) + 168)
#06 pc 0x1a064 libutils.so (android::Looper::pollInner(int) + 916)
#07 pc 0x19c68 libutils.so (android::Looper::pollOnce(int, int*, int*, void**) + 112)
#08 pc 0x118b3c 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:193)
       at android.app.ActivityThread.main(ActivityThread.java:8096)
       at java.lang.reflect.Method.invoke(Native method)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)

crashlytics_ss_1 crashlytics_ss_2 crashlytics_ss_3

[βœ“] Flutter (Channel stable, 3.13.5, on macOS 14.4.1 23E224 darwin-arm64, locale tr)
    β€’ Flutter version 3.13.5 on channel stable at /Users/cengizhan/Development/flutter
    β€’ Upstream repository https://github.com/flutter/flutter.git
    β€’ Framework revision 12fccda598 (8 ay ΓΆnce), 2023-09-19 13:56:11 -0700
    β€’ Engine revision bd986c5ed2
    β€’ Dart version 3.1.2
    β€’ DevTools version 2.25.0

[βœ“] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    β€’ Android SDK at /Users/cengizhan/Development/sdk
    β€’ Platform android-34, build-tools 34.0.0
    β€’ ANDROID_HOME = /Users/cengizhan/Development/sdk
    β€’ Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    β€’ Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    β€’ All Android licenses accepted.

[βœ“] Xcode - develop for iOS and macOS (Xcode 15.3)
    β€’ Xcode at /Applications/Xcode.app/Contents/Developer
    β€’ Build 15E204a
    β€’ CocoaPods version 1.12.1

[βœ“] Chrome - develop for the web
    β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[βœ“] Android Studio (version 2023.2)
    β€’ Android Studio at /Applications/Android Studio.app/Contents
    β€’ Flutter plugin can be installed from:
      πŸ”¨ https://plugins.jetbrains.com/plugin/9212-flutter
    β€’ Dart plugin can be installed from:
      πŸ”¨ https://plugins.jetbrains.com/plugin/6351-dart
    β€’ android-studio-dir = /Applications/Android Studio.app
    β€’ Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[βœ“] VS Code (version 1.89.1)
    β€’ VS Code at /Applications/Visual Studio Code.app/Contents
    β€’ Flutter extension version 3.76.0

[βœ“] Connected device (2 available)
    β€’ macOS (desktop) β€’ macos  β€’ darwin-arm64   β€’ macOS 14.4.1 23E224 darwin-arm64
    β€’ Chrome (web)    β€’ chrome β€’ web-javascript β€’ Google Chrome 125.0.6422.76

[βœ“] Network resources
    β€’ All expected network resources are available.

β€’ No issues found!

Packages

firebase_core: ^2.21.0 firebase_messaging: ^14.7.3

Reproducing the issue

  1. Launch the application on an Android device.
  2. Send multiple push notifications to the device within a short period.
  3. Notice the delay in receiving subsequent notifications.
  4. After some time, observe all pending notifications being delivered simultaneously, leading to a crash of the application.

Firebase Core version

2.21.0

Flutter Version

3.13.5

Relevant Log Output

main (native):tid=1 systid=18662 
#00 pc 0x86f8c libc.so (syscall + 28)
#01 pc 0x1b07a4 libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*) + 148)
#02 pc 0x3a544c libart.so (art::JNI<false>::CallObjectMethodV(_JNIEnv*, _jobject*, _jmethodID*, std::__va_list) + 500)
#03 pc 0x4074 libnativehelper.so (_JNIEnv::CallObjectMethod(_jobject*, _jmethodID*, ...) + 124)
#04 pc 0xed358 libandroid_runtime.so (android::NativeDisplayEventReceiver::dispatchVsync(long, unsigned long, unsigned int) + 48)
#05 pc 0x93c28 libgui.so (android::DisplayEventDispatcher::handleEvent(int, int, void*) + 168)
#06 pc 0x1a064 libutils.so (android::Looper::pollInner(int) + 916)
#07 pc 0x19c68 libutils.so (android::Looper::pollOnce(int, int*, int*, void**) + 112)
#08 pc 0x118b3c 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:193)
       at android.app.ActivityThread.main(ActivityThread.java:8096)
       at java.lang.reflect.Method.invoke(Native method)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)

Flutter dependencies

Expand Flutter dependencies snippet

Replace this line with the contents of your `flutter pub deps -- --style=compact`.

Additional context and comments

No response

Cengizhanerturan avatar May 27 '24 09:05 Cengizhanerturan

Can you upgrade you firebase plugins versions and try again and see if the issue still remains?

TarekkMA avatar May 27 '24 11:05 TarekkMA

Can you upgrade you firebase plugins versions and try again and see if the issue still remains?

@TarekkMA Thanks for your answer.

I need to update the flutter version in order to update the firebase versions, and this requires application-wide editing. For this reason, it doesn't seem possible for me to try this.

However, I shared screenshots showing the anrs received by users and the situations in which these anrs were received. Don't you think these screenshots document that anr occurs when a notification is received?

Cengizhanerturan avatar May 28 '24 11:05 Cengizhanerturan

When a notification is sent while the application is in the foreground, it crashes with the android.os.MessageQueue.nativePollOnce (Native method) error. There is no issue with the first notification; it arrives promptly. However, subsequent notifications experience delays. After a while, all pending notifications arrive simultaneously, leading to a crash of the application.

Also, apart from the problem I mentioned here, there may be another problem on the firebase_messaging side. As I mentioned before, there is a notification activation in all received anr and anr occurs after this notification activity.

Cengizhanerturan avatar May 28 '24 11:05 Cengizhanerturan

Can you make a reproduction repo where this issue is happening? just the code that causes this issue to happen.

TarekkMA avatar May 28 '24 12:05 TarekkMA

Can you make a reproduction repo where this issue is happening? just the code that causes this issue to happen.

@TarekkMA I cannot catch this problem, I am writing it here as a result of the notifications received by users using the application via Crashlytics.

Cengizhanerturan avatar May 29 '24 08:05 Cengizhanerturan

My report is not related firebasse_messaging. Sorry for the confusion. See below. https://github.com/ryanheise/audio_service/issues/875#issuecomment-2177815595

Same here.

Case1. Only android 14

          main (native):tid=1 systid=29182 
#00 pc 0x57840 libc.so (syscall + 32) (BuildId: 37f537c2ba9dcbb262a0a68f41a21da4)
#01 pc 0x232858 libart.so (art::ConditionVariable::WaitHoldingLocks + 140) (BuildId: 02bec5940be704b863f6514fc7d81c41)
#02 pc 0x55c044 libart.so (art::JNI<false>::CallObjectMethodV + 1140) (BuildId: 02bec5940be704b863f6514fc7d81c41)
#03 pc 0xe3994 libandroid_runtime.so (_JNIEnv::CallObjectMethod + 124) (BuildId: d29fc9115b65377a1a4cf15b069b9c2a)
#04 pc 0x153f70 libandroid_runtime.so (android::NativeDisplayEventReceiver::dispatchVsync + 68) (BuildId: d29fc9115b65377a1a4cf15b069b9c2a)
#05 pc 0xcba88 libgui.so (android::DisplayEventDispatcher::handleEvent + 280) (BuildId: 37fabcd36f9bbf3a645c2964fe397e4e)
#06 pc 0x18b70 libutils.so (android::Looper::pollInner + 1252) (BuildId: d0c24e3b7b6c7152eb82e77a5d2271e6)
#07 pc 0x18628 libutils.so (android::Looper::pollOnce + 124) (BuildId: d0c24e3b7b6c7152eb82e77a5d2271e6)
#08 pc 0x18f208 libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce + 48) (BuildId: d29fc9115b65377a1a4cf15b069b9c2a)
       at android.os.MessageQueue.nativePollOnce(Native method)
       at android.os.MessageQueue.next(MessageQueue.java:335)
       at android.os.Looper.loopOnce(Looper.java:187)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8919)
       at java.lang.reflect.Method.invoke(Native method)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

Every Crashlytics report comes from Android 14

image

Case2. Android 11 ~ 14

          main (native):tid=1 systid=20182 
#00 pc 0x4deb0 libc.so (syscall + 32) (BuildId: 81e690796099642123738ebc3a07936c)
#01 pc 0x232858 libart.so (art::ConditionVariable::WaitHoldingLocks + 140) (BuildId: 02bec5940be704b863f6514fc7d81c41)
#02 pc 0x555134 libart.so (art::JNI<false>::FindClass + 1836) (BuildId: 02bec5940be704b863f6514fc7d81c41)
#03 pc 0x1269a8 libandroid_runtime.so (android::NativeDisplayEventReceiver::dispatchVsync + 80) (BuildId: 495478b5d27456788ccd1d734fe53ee9)
#04 pc 0xb8a34 libgui.so (android::DisplayEventDispatcher::handleEvent + 204) (BuildId: 9d052c980f9c2cd86f54f2793428e7db)
#05 pc 0x1716c libutils.so (android::Looper::pollInner + 916) (BuildId: eee35419973f1d9330ba7fca3b3f5bf7)
#06 pc 0x16d6c libutils.so (android::Looper::pollOnce + 116) (BuildId: eee35419973f1d9330ba7fca3b3f5bf7)
#07 pc 0x166288 libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce + 48) (BuildId: 495478b5d27456788ccd1d734fe53ee9)
       at android.os.MessageQueue.nativePollOnce(Native method)
       at android.os.MessageQueue.next(MessageQueue.java:335)
       at android.os.Looper.loopOnce(Looper.java:186)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8855)
       at java.lang.reflect.Method.invoke(Native method)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

case2.txt case1-only android 14.txt

dfdgsdfg avatar Jun 12 '24 05:06 dfdgsdfg

My report is not related firebasse_messaging. Sorry for the confusion. See below. https://github.com/ryanheise/audio_service/issues/875#issuecomment-2177815595

https://issuetracker.google.com/issues/230950647#comment175

dfdgsdfg avatar Jun 12 '24 06:06 dfdgsdfg

@dfdgsdfg - thank you for locating the issue, it appears to be an underlying issue, possibly from firebase-android-sdk or even the android OS itself. Not much we can do about that on FlutterFire.

russellwheatley avatar Jun 12 '24 09:06 russellwheatley

My report is not related firebasse_messaging. Sorry for the confusion. See below. https://github.com/ryanheise/audio_service/issues/875#issuecomment-2177815595

https://github.com/firebase/firebase-android-sdk/issues/4345#issuecomment-2084281469

ANR (MessageQueue.nativePollOnce). The following are very helpful for solving firebase ANR. (1) GLSurfaceView will display ANR on Android 11. (I don't understand why this is related to firebase. ) https://issuetracker.google.com/issues/269158607 (2) You need to minimize the cold start time of the application as much as possible. https://medium.com/bumble-tech/how-we-achieved-a-6x-reduction-of-anrs-part-2-fixing-anrs-24fedf9a973f (3) My suggestion is not to use Firebase Crashlytics. The crash analysis of Google Play Console is sufficient for us to use. In poor network conditions, Crashlytics will block the main thread when the application first starts, increasing the cold start time by 3 seconds(This is to request a token.), and can also cause ANR(MessageQueue.nativePollOnce).

dfdgsdfg avatar Jun 17 '24 05:06 dfdgsdfg

@dfdgsdfg - thank you for locating the issue, it appears to be an underlying issue, possibly from firebase-android-sdk or even the android OS itself. Not much we can do about that on FlutterFire.

My report is not related firebasse_messaging. Sorry for the confusion. See below. https://github.com/ryanheise/audio_service/issues/875#issuecomment-2177815595

dfdgsdfg avatar Jun 19 '24 07:06 dfdgsdfg

Whenever a notification is received it causes ANR this issue should resolved ASAP

alihassan143 avatar Sep 24 '24 03:09 alihassan143

Any update on the above we are getting multiple ANR due to this

main (native):tid=1 systid=8702 #00 pc 0x99ccc libc.so (syscall + 28) (BuildId: e48f6233c3b033321b203dd90143e00e) #01 pc 0x22a220 libart.so (art::ConditionVariable::WaitHoldingLocks + 136) (BuildId: 27d824f901af23b82abd1f08138ee412) #02 pc 0x98fff8 libart.so (artJniMethodEnd + 344) (BuildId: 27d824f901af23b82abd1f08138ee412) #03 pc 0x784c3c libart.so (art_jni_method_end + 12) (BuildId: 27d824f901af23b82abd1f08138ee412) at android.os.MessageQueue.nativePollOnce(Native method) at android.os.MessageQueue.next(MessageQueue.java:350) at android.os.Looper.loopOnce(Looper.java:187) at android.os.Looper.loop(Looper.java:368) at android.app.ActivityThread.main(ActivityThread.java:8848) at java.lang.reflect.Method.invoke(Native method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)

Deepakkast avatar Oct 04 '24 06:10 Deepakkast

Please fix the above anr asap its creating negative impact in product

Deepakkast avatar Oct 09 '24 05:10 Deepakkast

I got the same error with

tnvietanh avatar Nov 01 '24 03:11 tnvietanh

Any updates on this? It’s causing a significant negative impact on the product. Please address this as soon as possible.

akshaydev1712 avatar Nov 08 '24 04:11 akshaydev1712

I got the same error with

firebase_core: 3.4.0 firebase_messaging: 15.1.0

    main (native):tid=1 systid=6392 

#00 pc 0xa277c libc.so (syscall + 28) (BuildId: b97e35df7ee74fe889cff6216e1664ba) #01 pc 0x260098 libart.so (art::ConditionVariable::WaitHoldingLocks + 136) (BuildId: 16f4d2c039392a9a00fff911131a8e12) #02 pc 0x771b3c libart.so (artJniMethodEnd + 428) (BuildId: 16f4d2c039392a9a00fff911131a8e12) #03 pc 0x20f9fc libart.so (art_jni_method_end + 12) (BuildId: 16f4d2c039392a9a00fff911131a8e12) at android.os.MessageQueue.nativePollOnce(Native method) at android.os.MessageQueue.next(MessageQueue.java:339) at android.os.Looper.loopOnce(Looper.java:176) at android.os.Looper.loop(Looper.java:328) at android.app.ActivityThread.main(ActivityThread.java:9231) at java.lang.reflect.Method.invoke(Native method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:594) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)

bingzhao0719 avatar Nov 26 '24 10:11 bingzhao0719

Got same issue. Any updates?

firebase_core: ^3.6.0 firebase_messaging: ^15.1.3

selawik avatar Dec 02 '24 08:12 selawik

Hi i got similar issue, there is a fix in firebase native sdk. https://github.com/firebase/firebase-android-sdk/issues/4345

It may worth it to update into firebase_core 3.7.0 or 3.8.0 https://github.com/firebase/flutterfire/blob/firebase_core-v3.7.0/packages/firebase_core/firebase_core/android/gradle.properties

alvarisi avatar Dec 05 '24 02:12 alvarisi

Same issue here... Any update?? firebase_core: ^3.9.0 firebase_messaging: ^15.1.6

Kircoo avatar Dec 26 '24 02:12 Kircoo

Same ANR problem with firebase_core: ^3.9.0 firebase_messaging: ^15.1.6 On devices (Galaxy note 10 lite - android 11 & Transsion Hot 11S & Xiaomi Redmi Note 10 - Android 12 ...)

there's same issue with firebase-sdk already existed https://github.com/firebase/firebase-unity-sdk/issues/671

elkhalifte avatar Dec 30 '24 10:12 elkhalifte

Facing similar issue, I'd say to push the issue w/ more reacts/thumbs up as this is important now: Image

mhmzdev avatar Dec 31 '24 04:12 mhmzdev

Has anyone been able to reproduce ANR reports from running locally? It should be possible from running in android studio using logcat I believe. Let me know if anyone was able to reproduce.

The stack trace makes it hard to diagnose as it doesn't point to anything in particular in the FlutterFire messaging plugin.

I am also curious if this is occurring on specific devices or android versions if you could provide those details.

Having a browse, it seems this is an issue for android Firebase in a number of different scenarios: https://github.com/search?q=repo%3Afirebase%2Ffirebase-android-sdk+at+android.os.MessageQueue.nativePollOnce%28Native+method%29&type=issues&p=1

Found this issue on issue tracker: https://issuetracker.google.com/issues/230950647?pli=1

This stackoverflow issue has some possible root causes: https://stackoverflow.com/questions/71478162/anr-at-android-os-messagequeue-nativepollonce

russellwheatley avatar Jan 02 '25 12:01 russellwheatley

This is a major issue. Happens to my flutter app in every few minutes in physical device, Android 14.

  firebase_core: 3.9.0
  firebase_messaging: 15.1.6

PhantomRay avatar Jan 05 '25 09:01 PhantomRay

Why my comment above is off-topic? I'm just confirming details on my side.

Now I also confirm that it's related to push notification. Every time when there is push notification coming in, the app will trigger ANR.

Same issue in Android 15.

PhantomRay avatar Jan 07 '25 10:01 PhantomRay

Same issue here... Any update on this!! firebase_core: ^3.9.0 firebase_messaging: ^15.1.6

srushti0104 avatar Mar 03 '25 09:03 srushti0104

@Cengizhanerturan I'm also experiencing this issue. How do you know it's caused by In-App Messaging? I recently disabled firebase_messaging, keeping only local notifications, and the problem still persists.

hirosz avatar Mar 05 '25 13:03 hirosz

It is quite evident that every time there is a push notification comes in, seconds later, ANR popup shows up.

PhantomRay avatar Mar 05 '25 13:03 PhantomRay

~~Gentlemen, while this is a tricky and painful issue to track the exact source of the problem, I've moved the code to Isolate.spawn and ANR disappeared!~~

PhantomRay avatar Mar 11 '25 03:03 PhantomRay

Gentlemen, while this is a tricky and painful issue to track the exact source of the problem, I've moved the code to Isolate.spawn and ANR disappeared!

@PhantomRay Can you provide a sample of how you did that? I think you cannot call platform-specific code in an isolate spawn

alihassan143 avatar Mar 11 '25 05:03 alihassan143

Indeed, it didn't work. Sorry about that. Had something to do with my testing cases.

PhantomRay avatar Mar 11 '25 06:03 PhantomRay