Skip to content

Commit

Permalink
Properly handle transaction commit errors (#3111)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstepanov authored Sep 9, 2024
1 parent 4c53743 commit 7c1b660
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public AsyncUsingReactiveTransactionOperations(ReactorReactiveTransactionOperati
}

@Override
public Optional<? extends DefaultAsyncTransactionStatus<?>> findTransactionStatus() {
public Optional<? extends AsyncTransactionStatus<?>> findTransactionStatus() {
return Optional.ofNullable(
reactiveTransactionOperations.getTransactionStatus(
ReactorPropagation.addPropagatedContext(Context.empty(), PropagatedContext.getOrEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ public <T> CompletionStage<T> withTransaction(TransactionDefinition definition,
// Last step to complete the TX, we need to use `withState` to properly setup thread-locals for the TX manager
result.whenComplete((o, throwable) -> {
if (throwable == null) {
synchronousTransactionManager.commit(status);
try {
synchronousTransactionManager.commit(status);
} catch (Throwable e) {
newResult.completeExceptionally(e);
return;
}
newResult.complete(o);
} else {
try {
synchronousTransactionManager.rollback(status);
} catch (Exception e) {
} catch (Throwable e) {
// Ignore rethrow
}
newResult.completeExceptionally(throwable);
Expand Down

0 comments on commit 7c1b660

Please sign in to comment.