i have something REALLY weird happening in my proj...
# announcements
n
i have something REALLY weird happening in my project right now.. one would expect a main function to implicitely do
exitProcess(0)
but it does not.. when i run this from within idea it just hangs at the end
b
Most likely you have some leaking coroutine
n
how would i debug that ? can Debugprobes help there ?
n
in general, any non-daemon thread could cause this
n
i narrowed it down to
val client = HttpClient(OkHttp)
somehow
n
maybe you need to
close()
it?
b
Yes, always remember to close http clent
Or just .use{} it
Leaked throught that plenty myself 😀
n
that used to not be a thing in the past i guess
g
It always been the thing with OkHttp, it creates own dispatcher with thread pool of non-daemon threads by default
n
hm...are there any static analysis tools that warn you if you don't close Closeable things? seems like IntelliJ should give you a warning or something
g
But how would such tool detect unclosed http client? Usually you want create an http client and use it until application is running, so it cached For command line utility it may be unnecessary, but it's not the most common use case It's the same as creating thread pool
n
I think any time something implementing Closeable isn't closed in the same scope it was created in, I'd like something to say "🤔 you know this needs to be closed, right?". even in this case, you could create a shutdown hook that closes the threadpool
g
I don't think so, not everything should be closed on the same scope, of course instead of cases when whole your program can be wrapped to one single scope
In case of okhttp you can configure it to create daemon threads
To fix original problem, but it will not have the same semantics as closing it explicitly, it will not cancel existing connections