Hey all! Anyone come across this issue with ktor 1...
# ktor
r
Hey all! Anyone come across this issue with ktor 1.4+ yet? Using Jackson content negotiation, JSON response objects greater than 4kb in size throw an exception
Exception 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:
Copy code
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/989b512bd7209735fd4d223b839d20d307c533c3
It's similar to some other issues I've seen, but I'm not using coroutines in my app code at all, and the reproduction is rather simple. I don't mind filing a youtrack ticket for this, but wanted to check here first.
Appears to be related to this commit from 1.4.2: https://github.com/ktorio/ktor/commit/0dfada8cd8e438d724ce77e9cd0d8b09a6b8c6dc#diff-9004ca70aa325dbcfa7d3ce09d193306f9f33bfd9c7c7732875f008e294feb6d For some reason larger responses that go through
ContentNegotiation
are ending up tying to
park()
with
ProhibitedParking
which leads to this exception
Copy code
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#L23
I'm assuming that exception is what's bringing this
CompletedContinuation
into the mix.
Maybe a missed call to
withBlockingAndRedispatch
? Hard to say, debugging threading issues isn't my bread and butter 😅