-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
TransactionalOperator
should not attempt to rollback after a failed commit
#27523
Comments
@mp911de any advice on this? |
The main difference between the imperative and the reactive transaction handling is that Reactor's |
What is the status on this? This is a very standard use case and our current solution is basically a copy-paste of the |
I have asked a feedback on the latest version of the PR here and will have a look after Mark feedback. |
We had to implement our custom reactive transaction manager for this but when we upgraded to Spring Boot 3 and updated r2dbc it stopped working. For some reason the isolation level cannot be set/passed to r2dbc. This can be reproduced with the following test (the second exception is thrown):
and the following configuration:
We are using:
The problem seems to be that spring-r2dbc:6.0.4:
spring-r2dbc:5.3.24:
Any ideas? |
@AntonioMorales97 Please create a dedicated issue if that's another bug. This issue will be handle via #27572 so I close it as a duplicate. |
Expected behavior
Using reactive transaction management, when a commit step fails in the
TransactionalOperator
, then the commit failure exception should be propagated. This can be for example aConcurrencyFailureException
.Actual behavior (Spring 5.3.9)
When a commit fails, the commit exception is logged & dropped in
TransactionalOperatorImpl
, and instead anIllegalTransactionStateException
is propagated.Practical case
When under high concurrency, our application is observing uninformative
IllegalTransactionStateException
like this:The above illegal transaction state seems to be overriding the propagation of this exception:
Investigation of the cause
The problem described above matches this warning on
ReactiveTransactionManager#rollback
:spring-framework/spring-tx/src/main/java/org/springframework/transaction/ReactiveTransactionManager.java
Lines 99 to 102 in fb7eea9
Looking at the current implementation of
TransactionalOperatorImpl
, it looks like indeed this can happen; iftransactionManager::commit
emits an error then a rollback will be attempted by theonErrorResume
:spring-framework/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionalOperatorImpl.java
Lines 74 to 84 in fb7eea9
Looks related to the discussion in #23562
Possible solution
The operators in
TransactionalOperatorImpl#transactional
could be restructured in such a way that rollbacks are not attempted after a failure to commit. Maybe this could be accomplished by moving therollbackOnException
to theasyncError
parameter in theusingWhen
. A similar approach should be applied inTransactionalOperatorImpl#execute
.Additionally, would it make sense to add the application exception as suppressed when the rollback in
rollbackOnException
emits an exception? This could make it easier to debug this and similar issues because currently the application exception is only linked when the rollback emits anTransactionSystemException
, but not in other cases likeIllegalTransactionStateException
.The text was updated successfully, but these errors were encountered: