Hi all! I have a Ktor server with a Netty engine....
# ktor
j
Hi all! I have a Ktor server with a Netty engine. On requests, I just call
delay
for some time (say 20 seconds) and then respond with a string. I thought that when I call
delay
, I can serve other requests while previous requests are suspended, but instead, I have to wait until those requests are done and only then I'm able to serve new requests. How can I serve new requests when my previous requests are suspended? I thought it works like that by default, but now I really don't understand.
m
It does work by default. The problem likely lies elsewhere in the server or the client. You need to share more about your setup to get to the root of this.
j
Are you calling delay in the middle of a DB transaction so you are blocking accessing to some data in the next call? Just a clue…
j
Copy code
fun main() {
    val req = AtomicInteger(0)
    embeddedServer(Netty, port = 8081, host = "127.0.0.1") {
        routing {
            static("/static") {
                resources()
            }
            get("/wait/{waitMillis}") {
                val r = req.incrementAndGet()
                log.debug("Got request $r")
                val waitMillis = call.parameters["waitMillis"]!!.toLong()
                delay(waitMillis)
                call.respondText("Hello, i've waited for ${waitMillis}ms")
                log.debug("Sent request $r")
            }
        }
    }.start(wait = true)
}
m
And the client?
j
Here is the code of a test application. When I do a lot of requests, I expect it to finish in
waitMillis
ms, but it processes requests almost one-by-one
just a browser requests in new tabs
m
Try curl, maybe the browser waits for each
🙌 1
j
Really, it was a browser issue. Thank you!
👍 1