launchdarkly / android-client-sdk

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

Occasional RejectedExecutionException is Activity onPause #265

Closed tevjef closed 2 months ago

tevjef commented 2 months ago

Describe the bug

We occasionally seeing this crash when our Activity pause. In our code if seems to occur when we're in the middle of closing one LDClient and initing another.

Caused by java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@4f892c2 rejected from java.util.concurrent.ScheduledThreadPoolExecutor@e99c8d3[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 8]
       at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2086)
       at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:848)
       at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:334)
       at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:562)
       at java.util.concurrent.Executors$DelegatedScheduledExecutorService.schedule(Executors.java:691)
       at com.launchdarkly.sdk.android.AndroidTaskExecutor.scheduleTask(AndroidTaskExecutor.java:42)
       at com.launchdarkly.sdk.android.AndroidPlatformState$ActivityCallbacks.onActivityPaused(AndroidPlatformState.java:248)
       at android.app.Application.dispatchActivityPaused(Application.java:465)
       at android.app.Activity.dispatchActivityPaused(Activity.java:1473)
       at android.app.Activity.onPause(Activity.java:2426)
       at androidx.fragment.app.FragmentActivity.onPause(FragmentActivity.java:282)
       at com.company.ui.activity.BaseActivity.onPause(BaseActivity.kt:114)
       at android.app.Activity.performPause(Activity.java:8485)
       at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1530)
       at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:5547)
       at android.app.ActivityThread.performPauseActivity(ActivityThread.java:5508)
       at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:5460)
       at android.app.servertransaction.PauseActivityItem.execute(PauseActivityItem.java:47)
       at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8663)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

SDK version 5.1.1

Language version, developer tools Kotlin 1.9.23 Gradle 8.7 AGP 8.3.2

OS/platform All versions of Android

Additional context Add any other context about the problem here.

tanderson-ld commented 2 months ago

Hi @tevjef , thank you for reporting this issue. Could you elaborate on what you mean by closing one LDClient and initing another? Usually LDClient.identify is used to switch contexts, such as when a user logs in/out.

tevjef commented 2 months ago

Hey @tanderson-ld, we are closing one client and opening another to change contexts. I was not aware of the LDIdentify.identify(). I'll try it out in out next release.

tanderson-ld commented 2 months ago

Well that's a relief to hear! Identify will also be much more performant. It seems highly likely that if you do switch to just calling identify that will likely resolve the issue.

Do you mind if I close this issue for now to help our team with tracking current issues? You are always more then welcome to reopen it if switching to identify doesn't resolve the issue.

tevjef commented 2 months ago

You may close the issue. Thank you.

tevjef commented 2 months ago

One strategy we have at our company to reduce startup times is to initialize LaunchDarkly on background thread. Is there a danger in doing so?

tevjef commented 2 months ago

@tanderson-ld Accidentally tagged incorrectly. The message above is direct at you. ^