Skip to content

Fix CompletableFuture exception handling #22476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

sviperll
Copy link

CompletableFuture exceptions are always wrapped into CompletionException.
We need to unwrap CompletionException to properly handle exceptions in MVC handlers that return CompletableFuture.
See https://stackoverflow.com/questions/49676889/spring-controller-advice-does-not-correctly-handle-a-completablefuture-completed

#22475

CompletableFuture exceptions are always wrapped into CompletionException.
We need to unwrap CompletionException to properly handle exceptions in MVC handlers that return CompletableFuture.
See https://stackoverflow.com/questions/49676889/spring-controller-advice-does-not-correctly-handle-a-completablefuture-completed
@pivotal-issuemaster
Copy link

@sviperll Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@sviperll Thank you for signing the Contributor License Agreement!

@jazdw
Copy link
Contributor

jazdw commented Apr 3, 2019

Can we get this merged? FWIW, it looks good to me.

@rstoyanchev rstoyanchev self-assigned this Apr 3, 2019
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 3, 2019
@rstoyanchev rstoyanchev added this to the 5.1.7 milestone Apr 3, 2019
rstoyanchev added a commit that referenced this pull request Apr 3, 2019
@rstoyanchev
Copy link
Contributor

I've resolved this in a separate commit also adding a check to ensure the cause is not null. Thanks for submitting a PR and for pointing this out!

@rstoyanchev rstoyanchev closed this Apr 3, 2019
@jhoeller jhoeller changed the title Fix CompletionFuture support Fix CompletableFuture exception handling Apr 9, 2019
@whiskeysierra
Copy link

Is this fix already part of a release?

@bclozel
Copy link
Member

bclozel commented Oct 30, 2019

Yes, Spring Framework 5.1.7

@Blackdread
Copy link

@bclozel weird, I am using Spring Boot v2.1.9.RELEASE but still have this error (dependency of spring is 5.1.10)

@maverick1601
Copy link
Contributor

I have the same problem, when returning e.g. CompletableFuture<ResponseEntity<Void>>from a controller method. The debugger revealed, that the DeferredResultMethodReturnValueHandlerisn't used in that case, since ResponseBodyEmitterReturnValueHandleris kicking in instead.

@rstoyanchev
Copy link
Contributor

@maverick1601, ResponseBodyEmitterReturnValueHandleris delegates to ReactiveTypeHandler which handles adapts the future via a Reactor-based adapter registered through the ReactiveAdapterRegistry. So this comes from Project Rector and I see a fix there reactor/reactor-core#1652 related to this for version 3.3. Spring Framework 5.2 is based on that version of Reactor but you can try independently upgrading Reactor first.

@maverick1601
Copy link
Contributor

Never mind, I figured, that it works as expected, just not via the DeferredResultMethodReturnValueHandler, as you've mentioned. The problem was on my side, testing with a mis-configured ExceptionHandler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants