amplitude / Amplitude-Kotlin

Amplitude Kotlin SDK
MIT License
27 stars 10 forks source link

[Crash] OutOfMemoryError crashes #179

Closed aurelhubert closed 7 months ago

aurelhubert commented 8 months ago

Expected Behavior

No OutOfMemory crashes

Current Behavior

We see a crazy number of crashes affecting a few users on Crashlytics (version 1.12.2):

This issue has 30,698 crash events affecting 7 users

Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 218125360 byte allocation with 25165824 free bytes and 118MB until OOM, target footprint 169589056, growth limit 268435456
       at java.util.Properties.loadConvert(Properties.java:546)
       at java.util.Properties.load0(Properties.java:390)
       at java.util.Properties.load(Properties.java:337)
       at com.amplitude.id.utilities.PropertiesFile.load(PropertiesFile.kt:22)
       at com.amplitude.id.FileIdentityStorage.<init>(FileIdentityStorage.kt:23)
       at com.amplitude.id.FileIdentityStorageProvider.getIdentityStorage(FileIdentityStorage.kt:71)
       at com.amplitude.core.Amplitude$build$built$1.invokeSuspend(Amplitude.kt:105)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
       at java.lang.Thread.run(Thread.java:1012)

Possible Solution

No idea

Steps to Reproduce

No idea

Environment

Screenshot 2024-01-31 at 12 11 32
phillipthelen commented 7 months ago

We started seeing this today as well. one user with over 1000 crashes in 4 days. The app crashes every two minutes for that user. From where the crash happens, could the issue be that the file storing properties somehow gets too big and then the SDK fails initialising every time because it tries to load the entire file into memory?

justin-fiedler commented 7 months ago

I believe the users are getting into a “crash loop”

The linked fix will catch the error, prevent a crash, and clear the "overloaded" file.

We will look more into the root cause and see if we can add better handling in a future PR.