micronaut-core
micronaut-core copied to clipboard
When using Controller with Project Reactor Mono doFinally is not called when request is cancelled
Expected Behavior
I have the following method in a controller:
@Get
fun testGet(): Mono<Long> {
logger.info("Received request")
return Mono.delay(Duration.ofMinutes(1))
.doFinally { signal ->
logger.info("Received signal: $signal")
}
}
I expect when I call the endpoint with curl and cancel the request, the reactive chain should be cancelled and the doFinally
block should be called with CANCEL
as signal.
Actual Behaviour
doFinally
is called after the duration of a minute with a ON_COMPLETE
signal. This means the Mono is not cancelled, and the request proceeds even when the client aborted it.
This behavior can be observed with GET and POST requests.
Steps To Reproduce
- Start example application
- use curl to either call with GET
http://localhost:8080
or with POSThttp://localhost:8080/post
- cancel request immediately after you see
Received request
in the logs - observe that after cancelling approximately a minute later, it logs:
Received signal: onComplete
Environment Information
No response
Example Application
https://github.com/getflip/micronaut-bugreports-demo/tree/reactor-doFinally-is-not-called-on-cancelled-request
Version
3.7.1