growthbook / growthbook-kotlin

GrowthBook Kotlin SDK
https://www.growthbook.io
MIT License
24 stars 20 forks source link

Caching Issue Leading to ANR in Production #145

Open zura-adod opened 1 week ago

zura-adod commented 1 week ago

I would like to report a caching issue I've encountered. While I haven't been able to reproduce the exact scenario, I have observed crashes in my production app, as detailed in the attached crash report. I'm not sure if this is related to a version mismatch or a known issue.

Here are the SDK versions we're using:

growthbook = "1.1.60" growthbookNetworkDispatcher = "1.0.2" The crash appears to be related to the following:

[com.sdk.growthbook.sandbox.CachingAndroid.getContent ANR triggered by slow operations on the main thread:

kotlinx.serialization.json.Json.decodeFromString (Json.kt:100) com.sdk.growthbook.sandbox.CachingAndroid.getContent (KMMCaching.kt:61) com.sdk.growthbook.sandbox.KMMCachingKt.getData (KMMCaching.kt:23) com.sdk.growthbook.features.FeaturesViewModel.fetchFeatures (FeaturesViewModel.kt:44) com.sdk.growthbook.features.FeaturesViewModel.fetchFeatures$default (FeaturesViewModel.kt:41) com.sdk.growthbook.GrowthBookSDK.refreshCache (GrowthBookSDK.kt:81) com.space.toolkits.feature.toggle.provider.impl.SPFeatureToggleImpl$startPeriodicCacheRefresh$1.invokeSuspend (SPFeatureToggleImpl.kt:151) kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33)](url)

Could anyone assist in identifying a possible fix or let me know if I might be missing something in my configuration?

Thank you for your help!

Bohdan-Kim commented 1 week ago

Is SPFeatureToggleImpl#startPeriodicCacheRefresh() method from your application?

nikantro888 commented 1 week ago

Yes, it's our method where we have written these lines of code:

  private fun startPeriodicCacheRefresh() {
        cacheRefreshJob = refreshCoroutineScope.launch(coroutineDispatchers.immediate) {
            while (isActive) {
                gb.refreshCache()
                // Call gb?.refreshCache() every 60 seconds
                delay(cacheRefreshInterval)
            }
        }
    }
vazarkevych commented 1 week ago

Hi, @nikantro888. We will check that and write to you.

Bohdan-Kim commented 1 week ago

try to wrap calling gb.refreshCache() with Dispatchers.IO

zura-adod commented 4 days ago

@Bohdan-Kim thanks for your response. We will try this approach in our next release and get back to you with the results.

vazarkevych commented 2 days ago

Hi, @zura-adod. Thank you, we will wait for that.