Closed
Description
Describe the bug
If a thread happens to start from a thread with different context class loader, then the class loader is retained for an unforeseeable time (at least for IDLE_WORKER_KEEP_ALIVE_NS
, may be longer under load). In multi-loader environment this causes a leak.
Provide a Reproducer
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
class MyClassLoader : ClassLoader()
fun main() {
val custom = MyClassLoader()
runBlocking {
val current = Thread.currentThread().contextClassLoader
try {
Thread.currentThread().contextClassLoader = custom
launch(Dispatchers.Default) {} // spawn new thread
}
finally {
Thread.currentThread().contextClassLoader = current
}
}
println("A place for breakpoint")
}
