https://kotlinlang.org logo
#ktor
Title
# ktor
h

Hyun

09/01/2020, 9:57 PM
Hi, guys, I have a problem on Ktor client native. I’ve been struggling to make the code below works after migrating kotlin to 1.4.0 version while migrating, I changed coroutine version to
1.3.9-native-mt
Copy code
class TestFreezingViewModel(val client: HttpClient) {

    fun call() {
         CoroutineScope(Dispatchers.Main).launch(start = CoroutineStart.LAZY) {
            try {
                client.get<String>("<https://test.com>") {}
            } catch (e: Throwable) {
                e.printStackTrace()
            }

        }.start()
    }
}

// swift side code
TestFreezingViewModel().call()
while the code running, The error(on the slack thread) occurs when Coroutine’s
invokeOnCompletion
is invoked, freeze() is called. and it tells that
HttpClient
can’t be frozen When I checked the source code HttpClient.init calls
preventFreeze()
I would like to know the intention of
preventFreeze
and what is the proper approach to use on developer’s side. Is there some advice?
Copy code
kotlin.native.concurrent.FreezingException: freezing of InvokeOnCompletion[InvokeOnCompletion@1b76e08] has failed, first blocker is HttpClient[io.ktor.client.engine.ios.IosClientEngine@1b1b748]
    at 0   kotlinIOS                           0x000000010bf93fed kfun:kotlin.Throwable#<init>(kotlin.String?){} + 93
    at 1   kotlinIOS                           0x000000010bf8cb9b kfun:kotlin.Exception#<init>(kotlin.String?){} + 91
    at 2   kotlinIOS                           0x000000010bf8cdeb kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 91
    at 3   kotlinIOS                           0x000000010bfc2c13 kfun:kotlin.native.concurrent.FreezingException#<init>(kotlin.Any;kotlin.Any){} + 643
    at 4   kotlinIOS                           0x000000010bfc4297 ThrowFreezingException + 231
    at 5   kotlinIOS                           0x000000010c0b2f4f FreezeSubgraph + 2815
    at 6   kotlinIOS                           0x000000010c0cc17b Kotlin_Worker_freezeInternal + 27
    at 7   kotlinIOS                           0x000000010bfc2d3e kfun:kotlin.native.concurrent#freeze@0:0(){0§<kotlin.Any?>}0:0 + 62
    at 8   kotlinIOS                           0x000000010c10c749 kfun:kotlinx.coroutines.JobSupport#invokeOnCompletion(kotlin.Boolean;kotlin.Boolean;kotlin.Function1<kotlin.Throwable?,kotlin.Unit>){}kotlinx.coroutines.DisposableHandle + 1881
    at 9   kotlinIOS                           0x000000010c10bf76 kfun:kotlinx.coroutines.JobSupport#invokeOnCompletion(kotlin.Function1<kotlin.Throwable?,kotlin.Unit>){}kotlinx.coroutines.DisposableHandle + 198
    at 10  kotlinIOS                           0x000000010c33b15b kfun:io.ktor.client.engine#createCallContext@io.ktor.client.engine.HttpClientEngine(kotlinx.coroutines.Job){}kotlin.coroutines.CoroutineContext + 1451
    at 11  kotlinIOS                           0x000000010c302d08 kfun:io.ktor.client.engine.HttpClientEngine.$executeWithinCallContextCOROUTINE$9.invokeSuspend#internal + 1048
    at 12  kotlinIOS                           0x000000010c303444 kfun:io.ktor.client.engine.HttpClientEngine.executeWithinCallContext#internal + 308
    at 13  kotlinIOS                           0x000000010c30420a kfun:io.ktor.client.engine.HttpClientEngine.$install$lambda-0COROUTINE$10.invokeSuspend#internal + 1562
    at 14  kotlinIOS                           0x000000010c304bf8 kfun:io.ktor.client.engine.HttpClientEngine.$install$lambda-0COROUTINE$10.invoke#internal + 312
    at 15  kotlinIOS                           0x000000010c29da5f kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal + 1135
    at 16  kotlinIOS                           0x000000010c29d0ab kfun:io.ktor.util.pipeline.SuspendFunctionGun.proceed#internal + 395
    at 17  kotlinIOS                           0x000000010c29d50a kfun:io.ktor.util.pipeline.SuspendFunctionGun.execute#internal + 474
    at 18  kotlinIOS                           0x000000010c295759 kfun:io.ktor.util.pipeline.Pipeline#execute(1:1;1:0){}1:0 + 361
    at 19  kotlinIOS                           0x000000010c326be5 kfun:io.ktor.client.features.HttpSend.DefaultSender.$executeCOROUTINE$27.invokeSuspend#internal + 1365
    at 20  kotlinIOS                           0x000000010c327244 kfun:io.ktor.client.features.HttpSend.DefaultSender.execute#internal + 308
    at 21  kotlinIOS                           0x000000010c324fbc kfun:io.ktor.client.features.HttpSend.Feature.$install$lambda-0COROUTINE$26.invokeSuspend#internal + 2236
    at 22  kotlinIOS                           0x000000010c3260f8 kfun:io.ktor.client.features.HttpSend.Feature.$install$lambda-0COROUTINE$26.invoke#internal + 312
    at 23  kotlinIOS                           0x000000010c29da5f kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal + 1135
    at 24  kotlinIOS                           0x000000010c29d0ab kfun:io.ktor.util.pipeline.SuspendFunctionGun.proceed#internal + 395
    at 25  kotlinIOS                           0x000000010c29d2a5 kfun:io.ktor.util.pipeline.SuspendFunctionGun.proceedWith#internal + 213
    at 26  kotlinIOS                           0x000000010c3173eb kfun:io.ktor.client.features.HttpCallValidator.Companion.$install$lambda-0COROUTINE$17.invokeSuspend#internal + 907
    at 27  kotlinIOS                           0x000000010c317c58 kfun:io.ktor.client.features.HttpCallValidator.Companion.$install$lambda-0COROUTINE$17.invoke#internal + 312
    at 28  kotlinIOS                           0x000000010c29da5f kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal + 1135
    at 29  kotlinIOS                           0x000000010c29d0ab kfun:io.ktor.util.pipeline.SuspendFunctionGun.proceed#internal + 395
2 Views