growthbook / growthbook-kotlin

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

Fatal Exception: kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 0: Expected start of the object #142

Open beinghassandar1 opened 2 months ago

beinghassandar1 commented 2 months ago

Hey guys, we are getting this crash on Android 13.

Can you guys please tell us why growth book is trying to deserialize <!DOCTYPE html><html lang="pt" from the backend instead of the actual json for features?

Lib Versions:

lib-growthbook = "1.1.61"
lib-growthbook-dispatcher = "1.0.0"
lib-growthbook = { module = "io.growthbook.sdk:GrowthBook", version.ref = "lib-growthbook" }
lib-growthbook-dispatcher = { module = "io.growthbook.sdk:NetworkDispatcherOkHttp", version.ref = "lib-growthbook-dispatcher" }

Initialization

  instance = GBSDKBuilder(
            apiKey = configHelper.getGrowthBookApiKey(),
            hostURL = configHelper.getGrowthBookUrl(),
            trackingCallback = { gbExperiment, gbExperimentResult ->
                Logging.d("$LOG_TAG - trackingCallback: Experiment Id: " + gbExperiment.key)
            },
            networkDispatcher = GBNetworkDispatcherOkHttp(httpClient),
            attributes = attributesMap,
        ).setRefreshHandler { isRefreshed, error ->
        }.setFeatureUsageCallback(featureUsageCallback = { featureKey, gbFeatureResult ->
        }).initialize()
Fatal Exception: kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 0: Expected start of the object '{', but had '<' instead at path: $
JSON input: <!DOCTYPE html><html lang="pt".....
       at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:24)
       at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:32)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.fail(AbstractJsonLexer.kt:598)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$default(AbstractJsonLexer.kt:596)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$kotlinx_serialization_json(AbstractJsonLexer.kt:233)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$kotlinx_serialization_json$default(AbstractJsonLexer.kt:228)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.unexpectedToken(AbstractJsonLexer.kt:225)
       at kotlinx.serialization.json.internal.StringJsonLexer.consumeNextToken(StringJsonLexer.kt:74)
       at kotlinx.serialization.json.internal.StreamingJsonDecoder.beginStructure(StreamingJsonDecoder.kt:102)
       at com.sdk.growthbook.features.FeaturesDataModel$$serializer.deserialize(FeaturesDataModel.kt:10)
       at com.sdk.growthbook.features.FeaturesDataModel$$serializer.deserialize(FeaturesDataModel.kt:10)
       at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69)
       at kotlinx.serialization.json.Json.decodeFromString(Json.kt:107)
       at com.sdk.growthbook.features.FeaturesDataSource$fetchFeatures$1.invoke(FeaturesDataSource.kt:42)
       at com.sdk.growthbook.features.FeaturesDataSource$fetchFeatures$1.invoke(FeaturesDataSource.kt:40)
       at com.sdk.growthbook.network.GBNetworkDispatcherOkHttp$consumeGETRequest$1$1.onResponse(GBNetworkDispatcherOkHttp.kt:61)
       at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
       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)
Fatal Exception: kotlinx.serialization.json.internal.JsonDecodingException
Expected start of the object '{', but had 'EOF' instead at path: $ JSON input:
kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException (JsonExceptions.kt:24)
kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException (JsonExceptions.kt:32)
kotlinx.serialization.json.internal.AbstractJsonLexer.fail (AbstractJsonLexer.kt:598)
kotlinx.serialization.json.internal.AbstractJsonLexer.fail$default (AbstractJsonLexer.kt:596)
kotlinx.serialization.json.internal.AbstractJsonLexer.fail$kotlinx_serialization_json (AbstractJsonLexer.kt:233)
kotlinx.serialization.json.internal.AbstractJsonLexer.fail$kotlinx_serialization_json$default (AbstractJsonLexer.kt:228)
kotlinx.serialization.json.internal.AbstractJsonLexer.unexpectedToken (AbstractJsonLexer.kt:225)
kotlinx.serialization.json.internal.StringJsonLexer.consumeNextToken (StringJsonLexer.kt:77)
kotlinx.serialization.json.internal.StreamingJsonDecoder.beginStructure (StreamingJsonDecoder.kt:102)
com.sdk.growthbook.features.FeaturesDataModel$$serializer.deserialize (FeaturesDataModel.kt:10)
com.sdk.growthbook.features.FeaturesDataModel$$serializer.deserialize (FeaturesDataModel.kt:10)
kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue (StreamingJsonDecoder.kt:69)
kotlinx.serialization.json.Json.decodeFromString (Json.kt:107)
com.sdk.growthbook.features.FeaturesDataSource$fetchFeatures$1.invoke (FeaturesDataSource.kt:42)
com.sdk.growthbook.features.FeaturesDataSource$fetchFeatures$1.invoke (FeaturesDataSource.kt:40)
com.sdk.growthbook.network.GBNetworkDispatcherOkHttp$consumeGETRequest$1$1.onResponse (GBNetworkDispatcherOkHttp.kt:61)
okhttp3.internal.connection.RealCall$AsyncCall.run (RealCall.kt:519)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1137)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:637)
java.lang.Thread.run (Thread.java:1015)
madhuchavva commented 2 months ago

@beinghassandar1 Do you mind checking if you're using the right endpoint/config ?

beinghassandar1 commented 2 months ago

We are using our self hosted api endpoint. 99% of the users get correct data... Few users are getting Json from the same endpoint.

vazarkevych commented 2 months ago

Hi, @beinghassandar1. We will check that and get back to you asap.

beinghassandar1 commented 2 months ago

Thank you. Just fyi, we are seeing more crash reports for other Android versions too. Like Android 9, 11, 12, 13, 14. All of them are either of the 2 crashes in the message above.

vazarkevych commented 2 months ago

Thank you for the detailed information. It will help us fix that.

vazarkevych commented 2 months ago

We are using our self hosted api endpoint. 99% of the users get correct data... Few users are getting Json from the same endpoint.

But what actually highlights that 1 percent with not right information. Maybe some version or some properties?

beinghassandar1 commented 2 months ago

Hhmm, hard to say. They are all on the latest build as we have recently released the new version with Growthbook sdk implementation.

beinghassandar1 commented 2 months ago

We are also getting more reports now but the crash is always something to do with wrong json.

    Fatal Exception: kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 0: Expected start of the object '{', but had '<' instead at path: $
JSON input: <!DOCTYPE html><html><noscript.....
       at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:24)
       at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:32)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.fail(AbstractJsonLexer.kt:598)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$default(AbstractJsonLexer.kt:596)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$kotlinx_serialization_json(AbstractJsonLexer.kt:233)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$kotlinx_serialization_json$default(AbstractJsonLexer.kt:228)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.unexpectedToken(AbstractJsonLexer.kt:225)
       at kotlinx.serialization.json.internal.StringJsonLexer.consumeNextToken(StringJsonLexer.kt:74)
       at kotlinx.serialization.json.internal.StreamingJsonDecoder.beginStructure(StreamingJsonDecoder.kt:102)
       at com.sdk.growthbook.features.FeaturesDataModel$$serializer.deserialize(FeaturesDataModel.kt:10)
       at com.sdk.growthbook.features.FeaturesDataModel$$serializer.deserialize(FeaturesDataModel.kt:10)
       at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69)
       at kotlinx.serialization.json.Json.decodeFromString(Json.kt:107)
       at com.sdk.growthbook.features.FeaturesDataSource$fetchFeatures$1.invoke(FeaturesDataSource.kt:42)
       at com.sdk.growthbook.features.FeaturesDataSource$fetchFeatures$1.invoke(FeaturesDataSource.kt:40)
       at com.sdk.growthbook.network.GBNetworkDispatcherOkHttp$consumeGETRequest$1$1.onResponse(GBNetworkDispatcherOkHttp.kt:61)
       at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
       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)
madhuchavva commented 2 months ago

@beinghassandar1 Is there a pattern you see on these crash errors? the 1% users are consistently getting this error? if it consistent, is there a way for you to replicate this error?

vazarkevych commented 1 month ago

Hi, @beinghassandar1 . After what steps did these users receive that, and what options did the user enable?

beinghassandar1 commented 1 month ago

Hey, When user logins and we initialize the sdk, we see a crash from there users. Its not even 1% now. Its more than that. I saw 450+ crashes for 116 users. All are for the same reason. The json is not valid.

Also, I got a new crash log.

ourserver_url = the url of our own hosting server

    Fatal Exception: kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 0: Expected start of the object '{', but had 'r' instead at path: $
JSON input: relay failed to <ourserver_url>:3100
       at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:24)
       at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:32)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.fail(AbstractJsonLexer.kt:598)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$default(AbstractJsonLexer.kt:596)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$kotlinx_serialization_json(AbstractJsonLexer.kt:233)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$kotlinx_serialization_json$default(AbstractJsonLexer.kt:228)
       at kotlinx.serialization.json.internal.AbstractJsonLexer.unexpectedToken(AbstractJsonLexer.kt:225)
       at kotlinx.serialization.json.internal.StringJsonLexer.consumeNextToken(StringJsonLexer.kt:74)
       at kotlinx.serialization.json.internal.StreamingJsonDecoder.beginStructure(StreamingJsonDecoder.kt:102)
       at com.sdk.growthbook.features.FeaturesDataModel$$serializer.deserialize(FeaturesDataModel.kt:10)
       at com.sdk.growthbook.features.FeaturesDataModel$$serializer.deserialize(FeaturesDataModel.kt:10)
       at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69)
       at kotlinx.serialization.json.Json.decodeFromString(Json.kt:107)
       at com.sdk.growthbook.features.FeaturesDataSource$fetchFeatures$1.invoke(FeaturesDataSource.kt:42)
       at com.sdk.growthbook.features.FeaturesDataSource$fetchFeatures$1.invoke(FeaturesDataSource.kt:40)
       at com.sdk.growthbook.network.GBNetworkDispatcherOkHttp$consumeGETRequest$1$1.onResponse(GBNetworkDispatcherOkHttp.kt:61)
       at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
       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)
vazarkevych commented 1 month ago

Hi, @beinghassandar1. Thank you for information, we will check that.

vazarkevych commented 1 week ago

Hi, we fixed that. Here is a link to PR. After merge it will be released