Hi Team, a customer is facing an error when enabli...
# sdk-kotlin
f
Hi Team, a customer is facing an error when enabling autoRefreshFeatures() in the Android SDK. From what I can see this may be related to a URL malfunction and I did notice a double // before the sdk param of the URL (see error). They are using GBSDKBuilder and have confirmed that they have not put a / before the sdk (clientKey). Attached is their query and assisted information. Is there anything that could be causing the double // ?
a
I was experiencing this issue. Then I changed my network dispatcher from Ktor to OkHttp and I received Successful result
Right now I'm using Ktor network dispatcher and
autoRefreshFeatures()
works fine. It is hard reproducible issue
image.png
Could you please ask customer to show us how his network dispatcher was configured? Which version of dispatcher is used? Which version of GrowthBook Kotlin SDK?
f
Thank you Bohdan, let me check in with him on this and get back to you šŸ™
šŸ™Œ 1
c
Thank you @flaky-noon-11399
šŸ™Œ 1
f
The customer responded with the following. I have also sent him the link to this thread so he can be directly looped in on all responses
šŸ™Œ 1
šŸ‘€ 1
c
Thank you very much @flaky-noon-11399
a
Maybe the customer has set small connect or read timeout? Could you please ask him to show how he has configured network dispatcher
About "I get neither error nor success", could you please ask the customer to upgrade to v1.0.6? It should be fixed in v1.0.6
šŸ™Œ 1
c
Thank you @ancient-car-96302. @flaky-noon-11399 could you please ask customer?
s
Hello @flaky-noon-11399, @ancient-car-96302, @calm-dog-24239 Thank you for the prompt replies, really appreciate it. • For the
NetworkDispatcher
, I was not adding any configuration. Just using the default
GBNetworkDispatcherKtor()
, which uses Ktor
HttpClient
. • After updating the dispatcher to v1.0.6, I'm getting the same
HttpRequestTimeoutException
(seems noting changed, just 1.0.5 had a bug?)
thankyou 1
a
Hello @silly-art-19522, Could you please try manually refresh with v1.0.6
s
I think it works. Let me try again.
yes, manual refresh works
šŸ‘ 2
Thank you @ancient-car-96302 for your time and help. We were able to figure out the issue. I'll just post here for reference. Basically, if the initialization is done in a suspend function, and we have something like this:
Copy code
suspend fun initializaSdk() {
    gbSdk = sdkBuilder.initialize()
    gbSdk.autoRefreshFeatures().collect {...
}
Than it errors. Launching
autoRefreshFeatures
in a separate coroutine solves it:
Copy code
suspend fun initializaSdk() {
    gbSdk = sdkBuilder.initialize()
    CoroutineScope(Dispatchers.IO).launch {
        gbSdk.autoRefreshFeatures().collect {...
    }
}
šŸ‘ 1
f
Thank you Vlad for sharing. Happy to hear all is now resolved šŸ™šŸ¾
s
@ancient-car-96302 we jumped to conclusion too soon 🤦 I had timeout set to 3 min. What we enabled with a separate launch was for it to work until it errors. So within those 3 mins it worked. But after 3 mins it errors, and not working anymore. I removed the 3 min timeout, and not it errors in 15s, so basically not working šŸ˜“.
It is not working at all. Reads as well. Only if I call to
refreshCache
after the error, than the reads will work.
I will try one more time outside of the suspend function to confirm if it will be the same.
So this is what I am doing now - I simplified it as much as possible to make sure it is not some sidecall making an issue (such as
.setQAMode
, etc. This is what I have now:
Copy code
fun initializeSdk() { // not suspend
    val sdkBuilder = GBSDKBuilder(
        apiKey = apiKey,
        hostURL = hostUrl,
        attributes = emptyMap(),
        trackingCallback = DefaultGBTrackingCallback(appPackage),
        networkDispatcher = GBNetworkDispatcherKtor(),
    )
    sdk = sdkBuilder.initialize()
    CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch {
       sdk.enableAutoRefresh()
    }
}

private suspend fun GrowthBookSDK.enableAutoRefresh() {
    autoRefreshFeatures().collectLatest {
        when (it) {
            is Resource.Success -> {
                GLog.v("FeatureFlags auto refreshed successfully.")
            }

            is Resource.Error -> {
                GLog.e(it.exception, "FeatureFlags auto refreshing failed!")
                refreshCache()
            }
        }
    }
}
Before it errors, the streaming (auto refresh) works, after timeout error (time can be set to control via Ktor HttpClient). After it errors it doesn't work. And reads don't work either. Calling to refreshCache() after error enables the reads to work.
c
Thank you @silly-art-19522 for sharing this. We will recheck that.
s
No worries @calm-dog-24239 Can you also confirm please, does the BE (cdn) close the connection to
autoRefreshFeatures
after 5-6 mins?