launchdarkly / android-client-sdk

LaunchDarkly Client-side SDK for Android
Other
45 stars 23 forks source link

ANR Caused by deadlock #162

Closed res0nance closed 2 years ago

res0nance commented 2 years ago

Is this a support request? This issue tracker is maintained by LaunchDarkly SDK developers and is intended for feedback on the SDK code. If you're not sure whether the problem you are having is specifically related to the SDK, or to the LaunchDarkly service overall, it may be more appropriate to contact the LaunchDarkly support team; they can help to investigate the problem and will consult the SDK team if necessary. You can submit a support request by going here or by emailing support@launchdarkly.com.

Note that issues filed on this issue tracker are publicly accessible. Do not provide any private account information on your issues. If your problem is specific to your account, you should submit a support request as described above.

Describe the bug There seems to be a deadlock in LaunchDarkly's SDK code

To reproduce Unable to provide direct steps to reproduce this issue but a stacktrace is provided below

Expected behavior LD should not cause ANRs

Logs

These two stack traces block each other.

com.launchdarkly.sdk.android.Throttler.attemptRun (Throttler.java:40)
com.launchdarkly.sdk.android.ConnectivityManager.startUp (ConnectivityManager.java:297)
com.launchdarkly.sdk.android.ConnectivityManager$3.onSuccess (ConnectivityManager.java:341)
com.launchdarkly.sdk.android.ConnectivityManager$3.onSuccess (ConnectivityManager.java:338)
com.launchdarkly.sdk.android.ConnectivityManager.voidSuccess (ConnectivityManager.java:273)
com.launchdarkly.sdk.android.ConnectivityManager.stopStreaming (ConnectivityManager.java:194)
com.launchdarkly.sdk.android.ConnectivityManager.reloadUser (ConnectivityManager.java:338)
com.launchdarkly.sdk.android.LDClient.identifyInternal (LDClient.java:313)
com.launchdarkly.sdk.android.LDClient.identifyInstances (LDClient.java:335)
com.launchdarkly.sdk.android.LDClient.identify (LDClient.java:301)
com.launchdarkly.sdk.android.ConnectivityManager.lambda$new$0 (ConnectivityManager.java:59)
com.launchdarkly.sdk.android.ConnectivityManager.$r8$lambda$nWWvGCieHvstn5YcNkEA7rFcAHs (ConnectivityManager.java)
com.launchdarkly.sdk.android.ConnectivityManager$$InternalSyntheticLambda$0$6761b2069fd0126b9b6e516b99ae60d1488c7998e41b5b3a6b9d3e61ee6bcf3b$0.run (ConnectivityManager.java)
com.launchdarkly.sdk.android.Throttler.run (Throttler.java:36)
com.launchdarkly.sdk.android.Throttler.$r8$lambda$0hIZ81XyILcbRmSVeAlWXsmjPCE (Throttler.java)
com.launchdarkly.sdk.android.Throttler$$InternalSyntheticLambda$1$47657271ca77a10c09f298b0fc296b8a4869f692acbfbf01e4d849ee7f0d0a78$2.run (Throttler.java)

SDK version 3.1.4

Language version, developer tools TargetSDK = 31 MinSDK = 21 KotlinVersion 1.6.10

OS/platform Android 12 also happens on Android 11 but given this issue it might be possible on any android version

louis-launchdarkly commented 2 years ago

Hello @res0nance, based on your stack track and the open ANR issue that we are investigating, given the variable is synchronized, we suspect that this has to do with the SDK's background updating behavior (in which the app is waiting for a response but the Android OS thinks the app is not doing anything and report an ANR). While we are gathering more information about this, can you please try to turn off the background updating behavior and see does the issue goes away?

https://github.com/launchdarkly/android-client-sdk/blob/ff3a0aba033425e6b0600819717a7836d1c4fe91/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDConfig.java#L538

Please report back if the issue still persists after the change.

res0nance commented 2 years ago

Hey @louis-launchdarkly , we unfortunately do not wish to disable the background updating, I've done some analysis and opened a PR which hopefully you can check out.

aengelberg commented 2 years ago

Your fix for this is in the 3.1.6 release. Thank you!