micronaut-core icon indicating copy to clipboard operation
micronaut-core copied to clipboard

When using Controller with Project Reactor Mono doFinally is not called when request is cancelled

Open nfode opened this issue 2 years ago • 1 comments

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

  1. Start example application
  2. use curl to either call with GET http://localhost:8080 or with POST http://localhost:8080/post
  3. cancel request immediately after you see Received request in the logs
  4. 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

nfode avatar Oct 10 '22 10:10 nfode