Closed klaasdellschaft closed 6 months ago
Looks like you have a point. Scheduled for the 6.0.1 release.
Hi @GuyPardon thanks for feedback and the quick fix in 6.0.1.
When I was looking at the code (and wondering how I would implement the fix), I was asking myself in how far concurrent threads (and thus potentially multiple calls to commit / rollback) need to be considered? At the moment, the interposed synchronizations may be added multiple times to the compositeTransaction if the commit would be called several times.
Do you have a use case for one JTA transaction shared by different threads?
No. It is just a question out of curiosity.
Implemented and tested for 6.0.1
Describe the bug Since 6.0.0, Atomikos supports the
TransactionSynchronizationRegistry
for registering interposed synchronizations. I need this functionality because I have aSynchronization
whoseafterCommit()
functionality needs to be executed before executing theafterCommit()
of other "regular" synchronizations.In case of committing a transaction, the interposed synchronizations work as expected, i.e. their
afterCommit()
is executed before any other "normal" synchronizations. However, in case of a rollback, the interposed synchronizations registered with the transaction do not get executed. Only the "normal" synchronizations are getting notified about the rollback of the transaction.To Reproduce Steps to reproduce the behavior:
TransactionSynchronizationRegistry
.transactions-jta:6.0.0
Additional context I think this behavior may be influenced on how the rollback got triggered. If the application first tries to do a commit of a transaction, and then gets a rollback, e.g. due to a constraint violation in the database, then the interposed synchronizations may also be executed. However, if the transaction was rolled back by the application itself, e.g. due to an exception being thrown in the application code, then the interposed synchronizations are not executed.
The reason is most likely available in how the interposed synchronizations are handled in
TransactionImp
. It seems to me, that only in case of a commit, the interposed synchronizations are registered with the compositeTransaction: https://github.com/atomikos/transactions-essentials/blob/master/public/transactions-jta/src/main/java/com/atomikos/icatch/jta/TransactionImp.java#L176However, if a rollback is triggered without a prior commit attempt, no registration of the interposed synchronizations with the compositeTransaction is taking place: https://github.com/atomikos/transactions-essentials/blob/master/public/transactions-jta/src/main/java/com/atomikos/icatch/jta/TransactionImp.java#L203