Skip to content

OutOfMemoryException and hundreds of launch darkly threads #234

@hoda0013

Description

@hoda0013

Describe the bug
We have been seeing hundreds of crashes over the past 3 months due to an OutOfMemoryException. The crashes are reported via Crashlytics which gives us a stacktrace with the crash and shows the other threads in the process and their stacktraces. What I'm seeing is that what this crash occurs there will be almost 300 other threads that are all created by the LaunchDarkly SDK. It seems like the number of threads created is probably what is causing the memory issue.

To reproduce
There doesn't seem to be a way to reproduce this that I have found. What I do know is that this only seems to be happening on devices that are running on a forked version of Android (PayDroid) made by a company called Pax. These are "payment terminals" used to process credit card transactions. We haven't seen any crashes on any other types of Android device.

Expected behavior
The LaunchDarkly SDK has some way of preventing so many threads from being created or can clean them up when they are finished running. If I view the crash logs for unrelated crashes, I'll see 2 threads with a the stacktrace I'm seeing not hundreds.

Logs
Here's the stacktrace from the crash:

Fatal Exception: java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again at java.lang.Thread.nativeCreate(Thread.java) at java.lang.Thread.start(Thread.java:730) at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:941) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1348) at com.launchdarkly.sdk.android.StreamUpdateProcessor.stop(StreamUpdateProcessor.java) at com.launchdarkly.sdk.android.ConnectivityManager.updateDataSource(ConnectivityManager.java:118) at com.launchdarkly.sdk.android.ConnectivityManager.lambda$new$0(ConnectivityManager.java:9) at com.launchdarkly.sdk.android.AndroidPlatformState$ConnectivityReceiver.onReceive(AndroidPlatformState.java:57) at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:1122) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:969) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:859)

Here's a stacktrace from one of the other threads created by LaunchDarkly. There are 291 other threads that have the seemingly the exact same stacktrace:

Thread-146: at java.lang.Object.wait(Object.java) at java.lang.Thread.parkFor$(Thread.java:2127) at sun.misc.Unsafe.park(Unsafe.java:325) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:161) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2035) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1058) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1118) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at com.launchdarkly.sdk.android.BackgroundThreadExecutor$PriorityThreadFactory.lambda$newThread$0(BackgroundThreadExecutor.java:23) at java.lang.Thread.run(Thread.java:761)

SDK version
4.2.3

Language version, developer tools
Kotlin 1.8.10

OS/platform
Android 7.1.1 (technical Pax PayDroid 7.1.1) and Android 5.1.1 (technically Pax PayDroid 5.1.1)

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions