Skip to content

Returning a CompletableFuture.failure() from an async, transactional method should mark the transaction as roll back #30018

Closed
@odrotbohm

Description

@odrotbohm

Returning a value from an @Async method usually involves a CompletableFuture wrapper of the value. If such a method is declared like this:

@Async
@Transactional
CompletableFuture<…> doSomething() {

  return someCondition
    ? CompletableFuture.completedFuture(…)
    : CompletedFuture.failedFuture(…);
}

The failed CF could be the result of handling an exception as we might not want to bubble up the async execution exception handling chain, but rather hand into the client so that it can react to the failure by e.g. ….exceptionally(…).

Unfortunately, for transactional methods, returning that failed CF instance would not roll back the transaction, as that currently only reacts to exceptions being thrown and Vavr Failure instances. Failed CF instances are actually very similar to the latter, which is why it would be nice if our transaction handling worked the same when returning failed CFs.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions