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

Nikky

11/27/2020, 8:38 PM
i have a global
val client = HttpClient(OkHttp)
and apparently it opens a coroutine / thread that is not closed when the program is done.. so it hangs i am not entirely sure what change on my side triggered this or if i am using it incorrectly if i do
exitProcess(0)
i can kill it but i'd prefer to avoid that more in 🧵
when i dumpt coroutines i see this:
Copy code
Coroutine "ktor-okhttp-context#11":StandaloneCoroutine{Active}@1d296da, state: SUSPENDED
	at io.ktor.client.engine.okhttp.OkHttpEngine$1.invokeSuspend(OkHttpEngine.kt:55)
	(Coroutine creation stacktrace)
	at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt.createCoroutineUnintercepted(IntrinsicsJvm.kt:122)
	at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:129)
	at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
	at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
	at io.ktor.client.engine.okhttp.OkHttpEngine.<init>(OkHttpEngine.kt:53)
	at io.ktor.client.engine.okhttp.OkHttp.create(OkHttp.kt:16)
	at io.ktor.client.HttpClientKt.HttpClient(HttpClient.kt:42)
b

Big Chungus

11/27/2020, 8:58 PM
Client is atomic. Use it and then close it
n

Nikky

11/27/2020, 9:09 PM
thanks.. replacing all cases of client usage with a
useClient { client -> ... }
fixed it
r

rudolf.hladik

11/29/2020, 7:24 PM
or call
client.close()
16 Views