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

Rafał Kuźmiński

12/07/2023, 6:20 PM
Hello. After migration to Tomcat10 and jakarta servlet our streamed responses stopped working. Code like this:
Copy code
call.respondOutputStream {
    write("Test".toByteArray())
    write("Stream".toByteArray())
    write(1)
}
works on tomcat9 and old servlet, but crashes on tomcat10 with:
Copy code
io.ktor.util.cio.ChannelWriteException: Failed to write to servlet async stream
	at io.ktor.server.servlet.jakarta.ServletWriter.wrapException(ServletWriter.kt:123)
	at io.ktor.server.servlet.jakarta.ServletWriter.onError(ServletWriter.kt:116)
	at io.ktor.server.servlet.jakarta.ServletWriter.run(ServletWriter.kt:56)
	at io.ktor.server.servlet.jakarta.ServletWriter$run$1.invokeSuspend(ServletWriter.kt)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
	Suppressed: java.io.IOException: io.ktor.util.cio.ChannelWriteException: Failed to write to servlet async stream
		at io.ktor.utils.io.jvm.javaio.OutputAdapter.close(Blocking.kt:134)
		at kotlin.io.CloseableKt.closeFinally(Closeable.kt:59)

...
Do you have any idea how to resolve this issue? Thanks!
a

Aleksei Tirman [JB]

12/08/2023, 9:24 AM
Can you please file an issue?
r

Rafał Kuźmiński

12/14/2023, 12:04 PM
@Aleksei Tirman [JB] Sure. I was tryting to get more information from our admin and now we found issue. Ktor is generating incorrect (doubled Transfer-Encoding) headers and our proxy (Traefik) is not allowing it. Is there any workaround to remove one of those headers from code?
a

Aleksei Tirman [JB]

12/14/2023, 3:13 PM
Can you please share a complete code snippet to reproduce the problem?
r

Rafał Kuźmiński

12/14/2023, 3:28 PM
Sorry I forgot to paste issue link here, glad you found it