The timeout will mark the transaction as rollback only. When the foo () ejb invocation completes the ejb container will try to commit the transaction and receive the rollback exception. We do not change the association in this case because there was a different outcome from the intended commit and the caller may want to ask for the transaction status. I think the container should handle that and disassociate the context, perhaps smarlow could comment on that.
+1 - it would be dangerous to leave the transaction associated with the caller thread in case they did something like this unexpectedly.
The second @Required would use a new transaction.
Originally, the EJB container org.jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction() was calling tm.commit() for all status except ROLLEDBACK. For ROLLEDBACK, we were calling tm.rollback. This had the problem of leaving failed transactions associated with the thread.
In 2013, we addressed that and more recently, switched to calling tm.rollback() for ROLLEDBACK/ROLLING_BACK (previously we called tm.suspend). For MARKED_ROLLBACK, we are also calling tm.rollback().
+1 for updating the container(s) to not leave ended transactions associated with the thread, as only the top level container knows when it is the correct time to clear the transaction.
I moved this to the WildFly discussions as it seems to pertain more to the behaviour of the application server.
I have diagnosed this issue thoroughly and it turns out that it is not a problem in server behaviour as disassociating thread from the context is part of standard rollback behaviour which is currently implemented in CMTTxInterceptor. The problem was caused by two bugs in narayana and CMTTxInterceptor itself. I prepared two pull requests that fix this issue: AtomicTransaction equals fix by tadamski · Pull Request #1044 · jbosstm/narayana · GitHub and CMTTxInterceptor transaction comparison fix by tadamski · Pull Request #9112 · wildfly/wildfly · GitHub. I'm closing this topic and moving the discussion to github.
Thanks for the contribution!