Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Transactions will never be rollbacked when in nested Unit Of Work #27

Open
mvonrenteln opened this issue Dec 7, 2018 · 0 comments
Open

Comments

@mvonrenteln
Copy link

mvonrenteln commented Dec 7, 2018

In JtaTransaction the rollback code seems to have a bug that prevents axon to rollback transactions if the error occurs in a nested unit of work.

 if (userTransaction.status == Status.STATUS_ACTIVE) {
                    if (owned) {
                        logger.debug("Rolling back BMT transaction.")
                        userTransaction.rollback()
                    } else {
                        logger.debug("Setting rollback for non-owned BMT transaction.")
                        userTransaction.setRollbackOnly()
                    }
                } else {

In the nested unit of work setRollbackOnly() will be executed on the transaction because it is not the "owner" of the transaction. The transaction status changes to ROLLBACK_ONLY. Back in the root unit of work (which is the owner) the transaction cannot be rollbacked because the status is not ACTIVE any more and the execution resumes with the else part... So the transaction will never be rollbacked.

Here is a log where this occured in our wildfly server. Because @TransactionManagement(BEAN) is selected the server states that "BMT bean should complete transaction before returning":

2018-12-06 17:48:07,405 INFO LoggingHandlerInterceptor EE-ManagedThreadFactory-kafka-Thread-1 - Command [XXX] => [null] (93 ms)
2018-12-06 17:48:07,405 DEBUG AbstractUnitOfWork EE-ManagedThreadFactory-kafka-Thread-1 - Committing Unit Of Work
2018-12-06 17:48:07,405 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Committing JTA transaction if required and possible.
2018-12-06 17:48:07,405 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Cannot commit non-owned BMT transaction.
2018-12-06 17:48:07,405 INFO LoggingHandlerInterceptor EE-ManagedThreadFactory-kafka-Thread-1 - Command [XXX2] => [null] (701 ms)
2018-12-06 17:48:07,405 DEBUG AbstractUnitOfWork EE-ManagedThreadFactory-kafka-Thread-1 - Committing Unit Of Work
2018-12-06 17:48:07,406 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Attempting to look up standard UserTransaction.
2018-12-06 17:48:07,406 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - In a BMT compatible context, using UserTransaction.
2018-12-06 17:48:07,406 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - We cannot own the BMT transaction, the current transaction status is Active.
2018-12-06 17:48:07,406 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Beginning JTA transaction if required and possible.
2018-12-06 17:48:07,406 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Did not try to begin non-owned BMT transaction.
2018-12-06 17:48:07,527 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Rolling back JTA transaction if required and possible.
2018-12-06 17:48:07,527 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Setting rollback for non-owned BMT transaction.
2018-12-06 17:48:07,528 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Rolling back JTA transaction if required and possible.
2018-12-06 17:48:07,528 WARN JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Cannot roll back BMT transaction, current transaction status is Marked for rollback.
2018-12-06 17:48:07,528 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Rolling back JTA transaction if required and possible.
2018-12-06 17:48:07,528 WARN JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Cannot roll back BMT transaction, current transaction status is Marked for rollback.
2018-12-06 17:48:07,528 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Rolling back JTA transaction if required and possible.
2018-12-06 17:48:07,528 WARN JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Cannot roll back BMT transaction, current transaction status is Marked for rollback.
2018-12-06 17:48:07,528 DEBUG JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Rolling back JTA transaction if required and possible.
2018-12-06 17:48:07,528 WARN JtaTransaction EE-ManagedThreadFactory-kafka-Thread-1 - Cannot roll back BMT transaction, current transaction status is Marked for rollback.
2018-12-06 17:48:07,536 ERROR [org.jboss.as.ejb3] (EE-ManagedThreadFactory-kafka-Thread-1) WFLYEJB0443: EJB 3.1 FR 13.3.3: BMT bean XXX should complete transaction before returning.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant