Thank you for your reply,but it seems that it didnt works well as expect.Could you please have a look about this.
Suppose that a vertx server was configured with a timeout(5s) setting ,and a long time(10s) was spent to compute result when request arrives.
Then it should be performed as below.
(1)In 5s,timeout exception will be thrown,and caught by failureHandler().The client get a timeout response.
(2)In 10s,the server get the result but the result would be ignored, because response has already sent.
This is the code:
```
package com.example.starter
import io.vertx.core.AbstractVerticle
import io.vertx.ext.web.Router
import io.vertx.ext.web.RoutingContext
import io.vertx.ext.web.handler.TimeoutHandler
class MainVerticle : AbstractVerticle() {
fun handlerStart(ctx: RoutingContext) {
println("handlerStart")
vertx.setTimer(5000){
ctx.fail(Exception("my_timeout_exception"))
}
vertx.executeBlocking<Void> {
Thread.sleep(10000)
ctx.next()
}
}
fun handlerEnd(ctx: RoutingContext) {
println("handlerEnd")
if (ctx.response().ended()) return
ctx.end("ok")
}
fun handlerFailure(ctx: RoutingContext) {
println("handlerFailure")
ctx.failure()?.message.also {
println(it)
}
ctx.end("failed")
}
fun handlerError(ctx: RoutingContext) {
println("handlerError")
ctx.failure()?.message.also {
println(it)
}
}
override fun start() {
vertx.exceptionHandler {
println(it)
}
val router = Router.router(vertx)
router.post().failureHandler(this::handlerFailure)
//
router.post().handler(TimeoutHandler.create(5000))
router.post().handler(this::handlerStart)
router.post().handler(this::handlerEnd)
router.errorHandler(500,this::handlerError)
vertx.createHttpServer()
.requestHandler(router)
.listen(9999)
}
}
```
Now I run the program on my machine,(1) was worked as expect,but in 10s ,another timeout exception (with same infomation) was thrown,and couldn't caught by failureHandler().
This exception was caused by .next(),and could be caught by errorHandler() which set for the whole router.In other words,customized exception "my_timeout_exception" was thrown twice.
It makes me so confused,not only because calling .next() throws exception,but also the exception is same as the previous.
Maybe vertx was designed that calling .next() is not allowed in failed RoutingContext,But I think it should be a exception with message like "calling next() is not allowed ,RoutingContext already failed"
The logs is
```
INFO: Succeeded in deploying verticle
handlerStart
handlerFailure
my_timeout_exception// in 5s
handlerError
my_timeout_exception // in 10s
```
I also tried to use TimeoutHandler.create(5000) to handle timeout ,but worse,logs shows that an exception was unhandled.
There is no chance to know what the exception is, because even vertx global exceptionHandler could not catching it.
```
INFO: Succeeded in deploying verticle
handlerStart
handlerFailure
null // in 5s.TimeoutHandler would not fail the ctx,so failure message is null.
Jun 22, 2022 3:19:57 AM io.vertx.ext.web.RoutingContext
SEVERE: Unhandled exception in router // in 10s
```
vertx version:4.3.1