Rob Hurkes
11/13/2020, 7:41 PMException in thread "eventLoopGroupProxy-3-6" kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[UnsafeBlockingTrampoline@762b17ae, Continuation at <http://io.ktor.utils.io|io.ktor.utils.io>.jvm.javaio.OutputAdapter$loop$1.loop(Blocking.kt:311)@64588a54]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
.
The actual cause is further down the stack trace:
Caused by: java.lang.ClassCastException: class kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to class kotlinx.coroutines.DispatchedContinuation (kotlin.coroutines.jvm.internal.CompletedContinuation and kotlinx.coroutines.DispatchedContinuation are in unnamed module of loader 'app')
at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:103)
I've got a minimal reproduction example up at https://github.com/rhurkes/ktor-playground/commit/989b512bd7209735fd4d223b839d20d307c533c3ContentNegotiation
are ending up tying to park()
with ProhibitedParking
which leads to this exception
java.lang.UnsupportedOperationException: Parking is prohibited on this thread. Most likely you are using blocking operation on the wrong thread/dispatcher that doesn't allow blocking. Consider wrapping you blocking code withContext(<http://Dispatchers.IO|Dispatchers.IO>) {...}.
because this work (regardless of size) ends up running through a withBlocking
here: https://github.com/ktorio/ktor/blob/master/ktor-http/jvm/src/io/ktor/http/content/OutputStreamContent.kt#L23CompletedContinuation
into the mix.withBlockingAndRedispatch
? Hard to say, debugging threading issues isn't my bread and butter 😅