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

Tech

03/10/2024, 12:58 AM
Hey does anyone know why whenever an invalid route is passed to the API StatusPages sends the request back twice? Checking if it was sent/committed doesn't resolve the issue.
I fixed it by adding a wild card route at the top of my
routing {}
scope and simply throwing a not found exception. When an invalid route is used it automatically returns HTTP 404 then my
statuses
block in
StatusPages
also picks it up which sends back two HTTP requests in the pipeline (to my understanding)
Copy code
route("{...}") {
            handle { throw ResourceNotFoundException() }
        }
a

Aleksei Tirman [JB]

03/11/2024, 7:37 AM
Can you share the complete code snippet?
t

Tech

03/11/2024, 3:02 PM
For what's causing the double call respond?
a

Aleksei Tirman [JB]

03/12/2024, 8:09 AM
I cannot reproduce your problem with the following code:
Copy code
embeddedServer(Netty, port = 8082) {
    install(StatusPages) {
        status(HttpStatusCode.NotFound) { call, _ ->
            call.respondText { "NOT FOUND" }
        }
    }

    routing {

    }
}.start(true)
And by making a
<http://localhost:8082/test>
request.
t

Tech

03/12/2024, 12:45 PM
Do you have call monitoring set up? When I’m available I’ll set up a repository
a

Aleksei Tirman [JB]

03/13/2024, 8:05 AM
It seems to be a buggy behavior. I've created an issue to address it.
t

Tech

03/13/2024, 10:54 PM
Gotcha, appreciate it
I'm not exactly sure if it's actually sending the request back twice or just logging it twice. I've had instances where the response times were different which makes me believe two requests are being sent back
a

Alex J.

03/20/2024, 4:52 AM
if it is listener/subscriber based there is a bug related to dev mode