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

com.android.installreferrer is called in the main thread which leads to ANR #1039

Open
5 tasks done
ddovod opened this issue Jan 17, 2022 · 25 comments
Open
5 tasks done

Comments

@ddovod
Copy link

ddovod commented Jan 17, 2022

Checklist before submitting a bug report

Java version

8

Android version

api 23+

Android SDK version

12.1

Installation platform & version

Gradle

Package

Other / I don't know

Goals

According to our investigations com.android.installreferrer can block the callers thread for a long time which in case of main thread leads to ANR. We call com.android.installreferrer from the background thread, it is safer and works just fine. Looks like fb sdk calls it from the main thread and we have a bunch of ANR reports that shows this case. Please consider moving com.android.installreferrer to the background thread. Thanks

Expected results

com.android.installreferrer is used in the background thread, no ANRs

Actual results

com.android.installreferrer is used in the main thread, ANRs

Steps to reproduce

No response

Code samples & details

Thread state: BLOCKED
android.os.BinderProxy.transactNative(BinderProxy.java:N)
android.os.BinderProxy.transact(BinderProxy.java:N)
e.c.a.a.a.XN(BaseProxy.java:N)
e.c.a.b.a.a$a$a.e(IGetInstallReferrerService.java:N)
com.android.installreferrer.api.InstallReferrerClientImpl.getInstallReferrer(InstallReferrerClientImpl.java:N)
com.facebook.internal.v$b.onInstallReferrerSetupFinished(InstallReferrerUtil.kt:N)
com.android.installreferrer.api.InstallReferrerClientImpl$InstallReferrerServiceConnection.onServiceConnected(InstallReferrerClientImpl.java:N)
android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:N)
android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:N)
android.os.Handler.handleCallback(Handler.java:N)
android.os.Handler.dispatchMessage(Handler.java:N)
android.os.Looper.loop(Looper.java:N)
android.app.ActivityThread.main(ActivityThread.java:N)
java.lang.reflect.Method.invoke(Method.java:N)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:N)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:N)

Edit: added a stacktrace

@Gell6
Copy link

Gell6 commented Feb 23, 2022

Can you give me script attack for apk???

@KulArtsiom
Copy link

KulArtsiom commented Apr 14, 2022

Hi guys!
I think ANR occur because you don't call the endConnection() on your InstallReferrerClient instance in tryConnectReferrerInfo function.

Information about it you can find in officially documentation

@MrAugMyo
Copy link

@Lok1n8
Copy link

Lok1n8 commented Mar 13, 2023

same issue

facebook-github-bot pushed a commit that referenced this issue Mar 21, 2023
Summary:
Fix issue #1039 , we'll need to end the connection to avoid leaks and performance problems.

https://developer.android.com/google/play/installreferrer/library#closing-connection

Reviewed By: wx0165927473

Differential Revision: D44238528

fbshipit-source-id: 868b108305c2aa964c91c2456309e45fd06e0070
@jasoncfpl
Copy link

same issue

@OldSlash
Copy link

Issue is not fixed, we observe exact the same issue on FBSDK 16.0.1

@EllieTellie
Copy link

EllieTellie commented May 4, 2023

@KylinChang

29af39e This commit most likely does not fix this issue as it is simply closing it but other parts of the system can still be slow on the binder call.

The issue is triggered by the call: referrerClient.installReferrer on line 41 in https://github.com/facebook/facebook-android-sdk/blob/main/facebook-core/src/main/java/com/facebook/internal/InstallReferrerUtil.kt

If you look at the source, it's a bit tricky to follow because it is obfuscated, for InstallReferrerClientImpl you will find it does the following:
this(((InstallReferrerClientImpl)super).service.c(bundle));
This then calls Transact on the IBinder which causes the ANR.

From the ANR dashboard:
The latency of a Binder call is hard to predict. It can be affected not only by the complexity of the call itself, but also by intermittent factors such as system server lock contention. You should treat them as you would treat I/O calls, and avoid, if possible, making Binder calls in the main thread. If making a Binder call from the main thread is unavoidable, make sure to instrument and monitor such calls to detect slowness.

So this ends up being called on the main thread because onInstallReferrerSetupFinished callback happens on the main thread.

I'm not an Android or Kotlin developer so unfortunately I have no easy fixes here, but this referrerClient.installReferrer call should probably be async.

@burak-cypher
Copy link

Any updates on this? Getting exactly the same ANR on Play Console, not so rare. Using Unity SDK 15.1.0.

@rampr
Copy link

rampr commented Jul 31, 2023

Having the same issue. Any updates here ?

@umeriqbalbutt
Copy link

Having the same issue any update on this ?

@AshikRaj
Copy link

We're on 16.2.0 and we're still seeing the same issue. Is there an update on when this will be fixed?

@rubenwe
Copy link

rubenwe commented Oct 29, 2023

Same issue here. Come on folks, please fix this!

@Holla-Chris
Copy link

Same issue:

"main" tid=1 Native
#00 pc 0x0000000000070950 /apex/com.android.runtime/lib/bionic/libc.so (__ioctl+8)
#1 pc 0x000000000003f04f /apex/com.android.runtime/lib/bionic/libc.so (ioctl+26)
#2 pc 0x0000000000039f87 /system/lib/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+238)
#3 pc 0x000000000003b07b /system/lib/libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*)+86)
#4 pc 0x000000000003ae1f /system/lib/libbinder.so (android::IPCThreadState::transact(int, unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+122)
#5 pc 0x00000000000356a7 /system/lib/libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+98)
#6 pc 0x00000000000c7e53 /system/lib/libandroid_runtime.so (android_os_BinderProxy_transact(_JNIEnv*, _jobject*, int, _jobject*, _jobject*, int)+82)
at android.os.BinderProxy.transactNative (Native method)
at android.os.BinderProxy.transact (BinderProxy.java:559)
at com.google.android.a.a.b (a.java:2)
at com.google.android.finsky.externalreferrer.IGetInstallReferrerService$Stub$Proxy.c (IGetInstallReferrerService.java:3)
at com.android.installreferrer.api.InstallReferrerClientImpl.getInstallReferrer (InstallReferrerClientImpl.java:5)
at com.facebook.internal.InstallReferrerUtil$tryConnectReferrerInfo$installReferrerStateListener$1.onInstallReferrerSetupFinished (InstallReferrerUtil.kt:41)
at com.android.installreferrer.api.InstallReferrerClientImpl$InstallReferrerServiceConnection.onServiceConnected (InstallReferrerClientImpl.java:4)
at android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:1972)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run (LoadedApk.java:2004)
at android.os.Handler.handleCallback (Handler.java:938)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:268)
at android.app.ActivityThread.main (ActivityThread.java:8016)
at java.lang.reflect.Method.invoke (Native method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:627)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:997)

@jygao
Copy link

jygao commented Feb 26, 2024

same issue

@manjeetcars24
Copy link

Any fix for this, we are also experiencing similar issue

@alkanyunus
Copy link

Also same here +1

@zahid-abstron
Copy link

at android.os.BinderProxy.transact (BinderProxy.java:571)
at com.google.android.finsky.externalreferrer.IGetInstallReferrerService$Stub$Proxy.getInstallReferrer (IGetInstallReferrerService.java:117)
at com.android.installreferrer.api.InstallReferrerClientImpl.getInstallReferrer (InstallReferrerClientImpl.java:187)
at com.facebook.internal.InstallReferrerUtil$tryConnectReferrerInfo$installReferrerStateListener$1.onInstallReferrerSetupFinished (InstallReferrerUtil.kt:41)
at com.android.installreferrer.api.InstallReferrerClientImpl$InstallReferrerServiceConnection.onServiceConnected (InstallReferrerClientImpl.java:222)
at android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:2095)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run (LoadedApk.java:2128)
at android.os.Handler.handleCallback (Handler.java:938)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loopOnce (Looper.java:201)
at android.os.Looper.loop (Looper.java:288)
at android.app.ActivityThread.main (ActivityThread.java:7881)
at java.lang.reflect.Method.invoke (Native method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:568)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1045)

Same Issue here,

@zhaowhao
Copy link

zhaowhao commented Apr 2, 2024

"main" tid=1 Native
  #00  pc 0x00000000000c9da8  /apex/com.android.runtime/lib64/bionic/libc.so (__ioctl+8)
  #01  pc 0x0000000000083888  /apex/com.android.runtime/lib64/bionic/libc.so (ioctl+156)
  #02  pc 0x0000000000056044  /system/lib64/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+292)
  #03  pc 0x0000000000057280  /system/lib64/libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*)+64)
  #04  pc 0x0000000000056fc4  /system/lib64/libbinder.so (android::IPCThreadState::transact(int, unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+224)
  #05  pc 0x000000000004eb18  /system/lib64/libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+312)
  #06  pc 0x0000000000169a84  /system/lib64/libandroid_runtime.so (android_os_BinderProxy_transact(_JNIEnv*, _jobject*, int, _jobject*, _jobject*, int)+400)
  at android.os.BinderProxy.transactNative (Native method)
  at android.os.BinderProxy.transact (BinderProxy.java:635)
  at com.google.android.finsky.externalreferrer.IGetInstallReferrerService$Stub$Proxy.getInstallReferrer (IGetInstallReferrerService.java:117)
  at com.android.installreferrer.api.InstallReferrerClientImpl.getInstallReferrer (InstallReferrerClientImpl.java:187)
  at com.facebook.internal.InstallReferrerUtil$tryConnectReferrerInfo$installReferrerStateListener$1.onInstallReferrerSetupFinished (InstallReferrerUtil.kt:41)
  at com.android.installreferrer.api.InstallReferrerClientImpl$InstallReferrerServiceConnection.onServiceConnected (InstallReferrerClientImpl.java:222)
  at android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:2186)
  at android.app.LoadedApk$ServiceDispatcher$RunConnection.run (LoadedApk.java:2219)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:233)
  at android.os.Looper.loop (Looper.java:344)
  at android.app.ActivityThread.main (ActivityThread.java:8212)
  at java.lang.reflect.Method.invoke (Native method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:584)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1034)

Same here.We've encountered the same ANR issue on Google Play Console. Does anyone have a solution for this?

@Ceikry
Copy link

Ceikry commented Apr 12, 2024

Also having the same issue here. It would be great if this was fixed, as it currently accounts for 30% of our ANRs.

@HemangiVekaria
Copy link

HemangiVekaria commented Aug 12, 2024

I am also facing similar ANR in my application. SS attached for log. I get this on google play console. This is increasing ANR rates. we want to decrease ANR. Please suggest solution. I am using Facebook SDK in my app for logging only.

implementation("com.facebook.android:facebook-android-sdk:17.0.0")

image

@SaMumcu
Copy link

SaMumcu commented Aug 26, 2024

Hello. We are also getting the same issue..

main (native):tid=1 systid=23898
#00 pc 0xaa878 libc.so (__ioctl + 8) (BuildId: 7841d31efc11481579e4cb75ccbcdb4f)
#1 pc 0x637bc libc.so (ioctl + 156) (BuildId: 7841d31efc11481579e4cb75ccbcdb4f)
#2 pc 0x5f294 libbinder.so (android::IPCThreadState::talkWithDriver + 280) (BuildId: a081f9ba71a90cdbd11dea0cd8482f02)
#3 pc 0x605f0 libbinder.so (android::IPCThreadState::waitForResponse + 60) (BuildId: a081f9ba71a90cdbd11dea0cd8482f02)
#4 pc 0x60330 libbinder.so (android::IPCThreadState::transact + 216) (BuildId: a081f9ba71a90cdbd11dea0cd8482f02)
#5 pc 0x7783c libbinder.so (android::BpBinder::transact + 188) (BuildId: a081f9ba71a90cdbd11dea0cd8482f02)
#6 pc 0x19908c libandroid_runtime.so (android_os_BinderProxy_transact + 152) (BuildId: ce775fd536cb61d44e2aa0f1afaf5b52)
at android.os.BinderProxy.transactNative(Native method)

Anyone used endConnection and fix the issue ?

facebook version: 16.0.0

@senrenbanka
Copy link

same issue. please consider use thread or executor just like other sdk do

https://github.com/adjust/android_sdk/blob/master/Adjust/sdk-core/src/main/java/com/adjust/sdk/InstallReferrer.java

@tinyrickguy
Copy link

same issue, please fix

@wgordy-infini
Copy link

Same issue. This ANR is our biggest offender in the Google Play Console and is causing our application to cross the bad behaviour threshold. This is likely causing thousands of apps to cross the bad behaviour threshold.

@AndreyZakharchenko-azur
Copy link

AndreyZakharchenko-azur commented Oct 15, 2024

Same here, stacktrace exactly the same as this one
Facebook SDK: 17.0.1

I am also facing similar ANR in my application. SS attached for log. I get this on google play console. This is increasing ANR rates. we want to decrease ANR. Please suggest solution. I am using Facebook SDK in my app for logging only.

implementation("com.facebook.android:facebook-android-sdk:17.0.0")

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests