Is there a way to make ktor fail (or detect in ano...
# ktor
p
Is there a way to make ktor fail (or detect in another way, perhaps statically?) if no response was sent for a given call/route? I have a non-deterministic problem with my server where sometimes the client doesn't get a response for a call, and I'm trying to debug it. I thought about writing a plugin that can make a call fail if no response was sent, but I thought I'll look around if it's already a solved problem.
Perhaps isHandled could be used in the plugin
r
ktor does have existing default handlers if no route handler actually handled the request, so you'll just need to make sure that your catch all plugin will run inbetween routes and the default handlers
a
Do you mean that the server sometimes closes a connection without sending an HTTP message?
p
probably yes, the exact message I see when calling a Kotlin Script that uses my server as a repository:
Copy code
[main] INFO org.jetbrains.kotlin.org.apache.http.impl.execchain.RetryExec - I/O exception (org.jetbrains.kotlin.org.apache.http.NoHttpResponseException) caught when processing request to {s}-><https://bindings.krzeminski.it:443>: The target server failed to respond
[main] INFO org.jetbrains.kotlin.org.apache.http.impl.execchain.RetryExec - Retrying request to {s}-><https://bindings.krzeminski.it:443>
or
Copy code
[main] INFO org.jetbrains.kotlin.org.apache.http.impl.execchain.RetryExec - I/O exception (java.net.SocketException) caught when processing request to {s}-><https://bindings.krzeminski.it:443>: Connection reset
[main] INFO org.jetbrains.kotlin.org.apache.http.impl.execchain.RetryExec - Retrying request to {s}-><https://bindings.krzeminski.it:443>
details: https://github.com/typesafegithub/github-workflows-kt/issues/1975
a
Ktor plugins won't detect low-level TCP/IP connection resets because the server engine (like Netty or Jetty) handles that. To diagnose, you can enable verbose logging for your specific Ktor server engine.
👍 1
p
@Aleksei Tirman [JB] CC @Vampire is there a guide/do you have experience with enabling verbose logging for Netty? even if we add
<Logger name="io.netty" level="ALL"/>
to the
log4j2.xml
, all what is printed is some debug info on startup - no details when making requests
👆 1
(I know that technically we could ask this question to the Netty folks, but since Netty is the recommended engine to start with for ktor, I think ktor should have minimal docs on this as well)
a
The diagnostic information should be logged only on failures. Can you please tell me if the read timeout is configured for the Netty engine, and which protocol (HTTP/1.1 or HTTP/2) is used when the server fails to send a response?
p
No explicit timeout (maybe there's some default). Regarding the version of HTTP, it's a question of what version the HTTP client in Kotlin Scripting uses to fetch Maven artifacts
I checked that Kotlin Scripting uses HTTP/1.1, checked by printing
call.request.httpVersion
in ktor handler when calling the service via Kotlin Scripting
a
Looking at the code, I can see two places where the connection is closed without the reason being logged. It's when the TLS handshake fails and when there is a read timeout. Read timeout is infinite by default.