firebase-android-sdk icon indicating copy to clipboard operation
firebase-android-sdk copied to clipboard

ANR in Firebase Analytics dynamite module: Main thread blocked on binder transaction in m7.ge.m (measurementdynamite)

Open lincolnrelias opened this issue 10 months ago • 14 comments

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: Ladybug 2024.2.1
  • Firebase Component: Analytics (via measurementdynamite dynamite module)
  • Component version: Firebase BOM 33.0.0 / measurementdynamite@[email protected]
  • Platform: Android TV (minSdk 24, targetSdk 35)

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

Firebase Analytics causes ANRs on Android TV devices when the measurementdynamite module performs a synchronous binder IPC call to Google Play Services on the main thread.

Impact: 100 ANR events affecting 57 users in the last 7 days.

What happens:

  1. App logs an analytics event via FirebaseAnalytics.logEvent()
  2. Event is dispatched to measurementdynamite dynamite module
  3. Module's internal Handler (m7.fx.handleMessage) processes event on the main thread
  4. Handler chain calls m7.ge.m() which makes a synchronous binder transaction
  5. Main thread blocks in IPCThreadState::waitForResponse() waiting for Google Play Services
  6. If Play Services is slow to respond (busy, restarting, memory pressure), ANR occurs

ANR Stack Trace (main thread): main (native):tid=1 systid=3300 #00 pc 0x71258 libc.so (__ioctl + 8) #01 pc 0x3f2cb libc.so (ioctl + 26) #02 pc 0x39c1b libbinder.so (android::IPCThreadState::talkWithDriver(bool) + 238) #03 pc 0x3a855 libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*) + 32) #04 pc 0x3a62b libbinder.so (android::IPCThreadState::transact(...) + 126) #05 pc 0x35327 libbinder.so (android::BpBinder::transact(...) + 98) #06 pc 0xc7ecf libandroid_runtime.so (android_os_BinderProxy_transact(...) + 82) at android.os.BinderProxy.transactNative(Native method) at android.os.BinderProxy.transact(BinderProxy.java:540) at m7.ge.m(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (180300-0):187) at m7.gb.a(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (180300-0):14) at m7.gd.b(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (180300-0):7) at m7.fu.c(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (180300-0):7) at m7.fx.handleMessage(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (180300-0):265) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:250) at android.app.ActivityThread.main(ActivityThread.java:7848)

Why this is not controllable by app developers: The blocking code is inside Google's measurementdynamite dynamite module (loaded from Google Play Services), not the Firebase SDK embedded in the app. Updating Firebase SDK version does not change this behavior.

Expected behavior: Firebase Analytics should not perform synchronous binder IPC on the main thread. Event processing should be fully asynchronous to prevent ANRs.

Suggested fix: Move the binder transaction in m7.ge.m() off the main thread or use asynchronous binder mechanisms.

Relevant Code:

// Standard Firebase Analytics usage - nothing unusual FirebaseAnalytics.getInstance(context).logEvent("event_name", bundle)

br.com.claro.now.smarttvclient_issue_28051541328b9d04813ec0dbc5ef264a_ANR_session_698147A7016700010CE4EF2BDFEB63B8_DNE_0_v2_stacktrace.txt

// The ANR occurs inside the dynamite module, not in app code. // App has no control over how measurementdynamite processes events.

lincolnrelias avatar Feb 04 '26 12:02 lincolnrelias

Hi @lincolnrelias, sorry for the late response and thank you for raising this issue. Let me raise this to our engineers for investigation and see what we can do here. I'll get back to you as soon as I hear back from the. Thanks!

lehcar09 avatar Mar 23 '26 16:03 lehcar09

This bug is tracked internally in b/495440438

lehcar09 avatar Mar 23 '26 17:03 lehcar09

I also have the same problem. erro info main (native):tid=1 systid=6933 #00 pc 0xd7854 libc.so (__ioctl + 4) #01 pc 0x93f68 libc.so (ioctl + 160) #02 pc 0x51cc4 libbinder.so (android::IPCThreadState::talkWithDriver(bool) + 300) #03 pc 0x52cd4 libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*) + 60) #04 pc 0x52a3c libbinder.so (android::IPCThreadState::transact(int, unsigned int, android::Parcel const&, android::Parcel*, unsigned int) + 188) #05 pc 0x4b0ac libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int) + 180) #06 pc 0x12c290 libandroid_runtime.so (android_os_BinderProxy_transact(_JNIEnv*, _jobject*, int, _jobject*, _jobject*, int) + 152) at android.os.BinderProxy.transactNative(Native method) at android.os.BinderProxy.transact(BinderProxy.java:593) at m7.ge.m(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):187) at m7.gb.a(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):14) at m7.gd.b(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):7) at m7.fu.c(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):7) at m7.fx.handleMessage(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):264) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:236) at android.app.ActivityThread.main(ActivityThread.java:8069) 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)

panmengquan-new avatar Mar 27 '26 08:03 panmengquan-new

Hey team, We’re still encountering this ANR and wanted to check if there’s any update or insight on it. This issue has been persisting for quite some time, and we’ve been unable to reliably reproduce it on our end. It appears to be a user-perceived ANR occurring across multiple Android OS versions. This is our top most ANR,

Last 7 days Affected Users : 144 Events : 198

We’re currently using firebaseBom = "34.3.0", and from the traces, the main thread is getting blocked in a Binder transaction involving Google Play Services (measurementdynamite), as shown below:

"main" tid=1 Native
#00  pc 0x00000000000e0bb8  /apex/com.android.runtime/lib64/bionic/libc.so (__ioctl+8)
#01  pc 0x0000000000097a3c  /apex/com.android.runtime/lib64/bionic/libc.so (ioctl+160)
#02  pc 0x000000000006c8ec  /system/lib64/libbinder.so (android::IPCThreadState::talkWithDriver+284)
#03  pc 0x000000000006db54  /system/lib64/libbinder.so (android::IPCThreadState::waitForResponse+76)
#04  pc 0x000000000006d890  /system/lib64/libbinder.so (android::IPCThreadState::transact+224)
#05  pc 0x0000000000059a70  /system/lib64/libbinder.so (android::BpBinder::transact+236)
#06  pc 0x000000000018007c  /system/lib64/libandroid_runtime.so (android_os_BinderProxy_transact+156)

at android.os.BinderProxy.transactNative (Native method)
at android.os.BinderProxy.transact (BinderProxy.java:646)
at m7.ge.m (:[email protected]:180)
...
at android.os.Looper.loop (Looper.java:300)
at android.app.ActivityThread.main (ActivityThread.java:8410)

cc : @lehcar09

prince-kumar001 avatar Apr 03 '26 06:04 prince-kumar001

Hey @lehcar09

We are facing the ANR and is our largest ANR now. Is there any update on the above? We’re currently using firebaseBom = "34.3.0"

"main" tid=1 Native
  #00  pc 0x00000000000d7b74  /apex/com.android.runtime/lib64/bionic/libc.so (__ioctl+4)
  #01  pc 0x0000000000093f70  /apex/com.android.runtime/lib64/bionic/libc.so (ioctl+160)
  #02  pc 0x0000000000051c7c  /system/lib64/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+300)
  #03  pc 0x0000000000052c8c  /system/lib64/libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*)+60)
  #04  pc 0x00000000000529f4  /system/lib64/libbinder.so (android::IPCThreadState::transact(int, unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+188)
  #05  pc 0x000000000004b0b0  /system/lib64/libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+152)
  #06  pc 0x00000000001270c0  /system/lib64/libandroid_runtime.so (android_os_BinderProxy_transact(_JNIEnv*, _jobject*, int, _jobject*, _jobject*, int)+152)
  at android.os.BinderProxy.transactNative (Native method)
  at android.os.BinderProxy.transact (BinderProxy.java:565)
  at m7.ge.m (:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):187)
  at m7.gb.a (:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):14)
  at m7.gd.b (:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):7)
  at m7.fu.c (:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):7)
  at m7.fx.handleMessage (:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):264)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:257)
  at android.app.ActivityThread.main (ActivityThread.java:8192)
  at java.lang.reflect.Method.invoke (Native method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:626)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1015)

akash-dey avatar Apr 07 '26 03:04 akash-dey

@lehcar09 one more report, is there any update on this?

main (native):tid=1 systid=30664 
#00 pc 0xc1de8 libc.so (__ioctl + 8) (BuildId: c3622b5c0a4cde0d723ea2d964ec71b7)
#01 pc 0x73d4c libc.so (ioctl + 156) (BuildId: c3622b5c0a4cde0d723ea2d964ec71b7)
#02 pc 0x614d8 libbinder.so (android::IPCThreadState::talkWithDriver + 280) (BuildId: 1fd6e2938b5c475563a7fa593f1fccb0)
#03 pc 0x6289c libbinder.so (android::IPCThreadState::waitForResponse + 60) (BuildId: 1fd6e2938b5c475563a7fa593f1fccb0)
#04 pc 0x625d8 libbinder.so (android::IPCThreadState::transact + 216) (BuildId: 1fd6e2938b5c475563a7fa593f1fccb0)
#05 pc 0x7aecc libbinder.so (android::BpBinder::transact + 188) (BuildId: 1fd6e2938b5c475563a7fa593f1fccb0)
#06 pc 0x19f9c8 libandroid_runtime.so (android_os_BinderProxy_transact + 152) (BuildId: 5c5f7c8a751f2a7da42af4e621fa2168)
       at android.os.BinderProxy.transactNative(Native method)
       at android.os.BinderProxy.transact(BinderProxy.java:599)
       at m7.fv.m(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (190400-0):180)
       at m7.fs.a(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (190400-0):14)
       at m7.fu.b(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (190400-0):7)
       at m7.fl.c(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (190400-0):7)
       at m7.fo.handleMessage(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (190400-0):264)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:205)
       at android.os.Looper.loop(Looper.java:294)
       at android.app.ActivityThread.main(ActivityThread.java:8391)
       at java.lang.reflect.Method.invoke(Native method)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:640)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)

vlonjat-gashi avatar May 13 '26 09:05 vlonjat-gashi

Same here. This is causing about 10% of all ANRs in our production app right now, so it's a pretty big deal for us. Any updates or workarounds on this?

pavlovrbw avatar May 14 '26 13:05 pavlovrbw

Any update? this is the #1 ANR in our app

zxia-sc avatar Jun 02 '26 00:06 zxia-sc

Hi @lehcar09, are there any updates on this issue? This has been one of the major ANR causes for us since January, and it's still happening daily After analyzing our device data, we noticed this seems to recur far more often on Spreadtrum/UNISOC T612 (devices like realme RE5C9F/RE58BC/RE6054), in case that helps to reproduce it Also providing a stacktrace:

"main" tid=1 Native
  #00  pc 0x00000000000ab9e8  /apex/com.android.runtime/lib64/bionic/libc.so (__ioctl+8)
  #01  pc 0x000000000005d99c  /apex/com.android.runtime/lib64/bionic/libc.so (ioctl+156)
  #02  pc 0x000000000005b5e8  /system/lib64/libbinder.so (android::IPCThreadState::talkWithDriver+280)
  #03  pc 0x000000000005c840  /system/lib64/libbinder.so (android::IPCThreadState::waitForResponse+112)
  #04  pc 0x000000000005c548  /system/lib64/libbinder.so (android::IPCThreadState::transact+216)
  #05  pc 0x0000000000053c8c  /system/lib64/libbinder.so (android::BpBinder::transact+188)
  #06  pc 0x0000000000176df8  /system/lib64/libandroid_runtime.so (android_os_BinderProxy_transact+152)
  at android.os.BinderProxy.transactNative (Native method)
  at android.os.BinderProxy.transact (BinderProxy.java:595)
  at m7.es.m (:com.google.android.gms.dynamite_measurementdynamite@[email protected] (190400-0):180)
  at m7.ep.a (:com.google.android.gms.dynamite_measurementdynamite@[email protected] (190400-0):14)
  at m7.er.b (:com.google.android.gms.dynamite_measurementdynamite@[email protected] (190400-0):7)
  at m7.ei.c (:com.google.android.gms.dynamite_measurementdynamite@[email protected] (190400-0):9)
  at m7.el.handleMessage (:com.google.android.gms.dynamite_measurementdynamite@[email protected] (190400-0):280)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loopOnce (Looper.java:201)
  at android.os.Looper.loop (Looper.java:288)
  at android.app.ActivityThread.main (ActivityThread.java:8194)
  at java.lang.reflect.Method.invoke (Native method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:703)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:911)

krebrishcheva avatar Aug 28 '26 07:08 krebrishcheva

I got the same issue, after checking i saw Firebase uses alot of "lock" for ther initialize progress which could cause lots of ANR in case of using Firebase from another thread.

january-lab avatar Sep 24 '26 02:09 january-lab

Image

xieming20230801 avatar Oct 21 '26 03:10 xieming20230801

Image Any progress? This ANR accounts for a significant portion of issues in our app.

yangfanCode avatar Oct 28 '26 15:10 yangfanCode

We also encountered this problem and hope it can be fixed as soon as possible.

ClayLinW avatar Nov 11 '26 10:11 ClayLinW