This is not a bug. This code creates a genuine deadlock. This code does runBlocking
inside stream.parallel()
which dispatches to CommonPool
(by default), so all the threads in common pool are blocked, but, at the same time, coroutines in this code are dispatched to the the same CommonPool
, which is blocked by runBlocking { deferred.await() }
, so they cannot execute. As a general rule, the code that runs inside parallel streams should never block (runBlocking
should not be used there). If this cannot be avoided, then coroutines shall be dispatched to a separate thread pool.
2 Likes