https://kotlinlang.org logo
#ktor
Title
# ktor
b

bitkid

11/26/2020, 12:18 PM
Hi! please help! 🙂 We are a few days from our release and stupid me upgraded to kotlin 1.4.20 and ktor 1.4.2 .. very simple handler:
Copy code
get("/test") {
            call.respondTextWriter(contentType = ContentType.Text.CSV) {
                repeat(100000) {
                    write("bla")
                }
            }
        }
result:
Copy code
Exception in thread "eventLoopGroupProxy-3-2" kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[UnsafeBlockingTrampoline@28448af8, Continuation at io.ktor.utils.io.jvm.javaio.OutputAdapter$loop$1.loop(Blocking.kt:311)@4245d158]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
	at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:93)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:64)
	at io.ktor.utils.io.jvm.javaio.UnsafeBlockingTrampoline.dispatch(Blocking.kt:296)
	at kotlinx.coroutines.DispatchedContinuation.resumeWith(DispatchedContinuation.kt:184)
	at io.ktor.utils.io.jvm.javaio.BlockingAdapter$end$1.resumeWith(Blocking.kt:163)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
	at io.ktor.utils.io.jvm.javaio.UnsafeBlockingTrampoline.dispatch(Blocking.kt:296)
	at kotlinx.coroutines.DispatchedContinuation.resumeWith(DispatchedContinuation.kt:184)
	at io.ktor.utils.io.internal.CancellableReusableContinuation.resumeWith(CancellableReusableContinuation.kt:93)
	at io.ktor.utils.io.ByteBufferChannel.resumeWriteOp(ByteBufferChannel.kt:2258)
	at io.ktor.utils.io.ByteBufferChannel.bytesRead(ByteBufferChannel.kt:929)
	at io.ktor.utils.io.ByteBufferChannel.consumed(ByteBufferChannel.kt:1953)
	at io.ktor.server.netty.cio.NettyResponsePipeline$processBodyFlusher$2.invokeSuspend(NettyResponsePipeline.kt:305)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.ktor.server.netty.EventLoopGroupProxy$Companion$create$factory$1$1.run(NettyApplicationEngine.kt:215)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:832)
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)
	at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:55)
	... 22 more
i am using the netty engine. and my test suite didnt catch that error, so when using TestApplicationEngine and handleRequest it works. but when i start the server and hit the endpoint with curl i get that exception.
is there any way to fix that without downgrading again?
when i use repeat(100) it works
so it seems there is some kind of threshold at work?
s

Satyam Agarwal

11/26/2020, 12:56 PM
b

bitkid

11/26/2020, 1:10 PM
ok so no solution in sight?
s

Satyam Agarwal

11/26/2020, 1:12 PM
I’d suggest that you make a small repo and share the code reproducing the problem and paste it on the ticket so that they can investigate and come up with a solution 🙂
b

bitkid

11/26/2020, 1:13 PM
lol .. you already wrote the failing code in the ticket .. its super simple to reproduce
c

carrot

11/26/2020, 4:15 PM
I’ve made a sample and submitted https://youtrack.jetbrains.com/issue/KTOR-1369 and linked the ticket 🙂
You can fix it by downgrading just the offending dependency to 1.4.1, if you’re using that. For us it was ‘ktor-Jackson’
b

bitkid

11/26/2020, 4:26 PM
hmm .. i think thats a different issue
4 Views