As demonstrated in https://github.com/sdeleuze/spring-boot-coroutines-demo, in annotated controller throwing a CancellationException
result in a 5xx error. Since CancellationException
means "normal cancellation of a coroutine", is it the expected behavior?
In functional controller, with such handler function:
suspend fun cancel(request: ServerRequest): ServerResponse {
throw CancellationException()
}
The related web endpoint never returns, that's unexpected and not consistent with the annotated variant (cc @poutsma). We should probably fix this, see https://github.com/sdeleuze/spring-boot-coroutines-demo/blob/master/src/test/kotlin/com/example/CoroutinesApplicationTests.kt#L63-L67 for a repro.
Comment From: sdeleuze
After a deeper analysis, I tend to think the incorrect behavior is more on @Controller
side since CancellationException
is not an error but a regular cancellation. What happens in that the cancellation processed here is recognized as incorrect because the cause is InvocationTargetException
not CancellationException
despite the unwrapping expected to be performed here.
Since there is no stakeholder yet and since it will require more thoughts, I move it to the 5.x backlog.
Comment From: sdeleuze
Closing this issue due to the lack of traction and the fact I am myself not sure we should handle CancellationException
differently. Handling it via a regular exception handling is maybe the most reasonable and unsurprising option.