i have a global `val client = HttpClient(OkHttp)` ...
# ktor
n
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
Client is atomic. Use it and then close it
n
thanks.. replacing all cases of client usage with a
useClient { client -> ... }
fixed it
r
or call
client.close()