launchdarkly / android-client-sdk

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

INVALID_RESPONSE_BODY when polling on background #152

Closed orafaaraujo closed 2 years ago

orafaaraujo commented 2 years ago

Describe the bug Hello,

We added some nonfatal in the listener LDStatusListener and we noticed a quantity of INVALID_RESPONSE_BODY when the app is in the background (346 non-fatal events affecting 293 users in the last 24 hours).

The LDFailure.message is Exception while handling flag fetch response The LDFailure.cause is mostly

java.io.IOException: gzip finished without exhausting source

But we also have many of

java.io.IOException: failed to rename /data/user/0/fr.vestiairecollective/cache/com.launchdarkly.http-cache/824d4750cb4389481dda7bf14c725579.0.tmp to /data/user/0/fr.vestiairecollective/cache/com.launchdarkly.http-cache/824d4750cb4389481dda7bf14c725579.0  3

So I would like to understand better the impact of this error, why it happens only in the background, and if there's something that we could do to avoid it.

To reproduce I couldn’t reproduce it locally.

Expected behavior Not having INVALID_RESPONSE_BODY, like it happens when the app is in the foreground.

SDK version 3.1.1

Language version, developer tools Kotlin 1.5.31, building with AGP 7.0.4 and Gradle 7.1

Let me know if you need more information. Thank you

orafaaraujo commented 2 years ago

Hello,

Here's the code used to start the library

// Creating anonymous user before having our session
val anonymousUser = LDUser.Builder("user key")
    .anonymous(true)
    .country(isoCountry)
    .build()

// Setting up two environments
val stageKeyName = "staging"
val secondaryMobileKeys: Map<String, String> = mutableMapOf(
    stageKeyName to "stage mobile key",
)

// Creating the LDConfig
val config: LDConfig = LDConfig.Builder()
    .mobileKey("prod mobile key")
    .secondaryMobileKeys(secondaryMobileKeys)
    .build()

LDClient.init(application, config, anonymousUser)
val client: LDClient =
    if (BuildConfig.DEBUG) {
        LDClient.getForMobileKey(stageKeyName)
    } else {
        LDClient.get()
    }

// Setting up our non fatal listener
client.registerStatusListener(
    object : LDStatusListener {
        override fun onConnectionModeChanged(connectionInfo: ConnectionInformation) {
            Log.d(TAG, "onConnectionModeChanged - connectionInfo = [$connectionInfo]")
        }

        override fun onInternalFailure(ldFailure: LDFailure) {
            // Tracking non fatal ignoring LDFailure.FailureType.NETWORK_FAILURE
            trackNonFatal(ldFailure)
        }
    }
)

I'm omitting more build types and custom attributes when creating a user, but this is the implementation to start the library.

Once the session is created, we update and alias the logged user.

louis-launchdarkly commented 2 years ago

Hello @orafaaraujo, thank you for your question. We don't have an obvious answer from our side yet and will need to look into this more.

Filed Internally as 143101.

louis-launchdarkly commented 2 years ago

Hello @orafaaraujo, thank you for reaching out to our Support. Because our Support team works with customers and developers like you all the time, they have a lot of experience helping people using our SDKs. I will close this for now and have the conversation through Support.