When firing an CDI event from a running transaction synchronisation, the TransactionalObserverNotifier fails to defer the notification, because registering the TransactionSynchronizedRunnable fails with an "ARJUNA016082: Synchronizations are not allowed". In my case this for example happens when I fire the event from a JPA Lifecycle listener, which is triggered by the flush call on the EntityManager through Hibernates JtaTransactionCoordinatorImpl bound in the JCAOrderedLastSynchronizationList. The current behaviour has one very odd side effect: namely, the exception is swallowed in the TransactionalObserverNotifier, which then notifies a filtered set of observers, assuming that a rollback exception must have occurred. As a result, the `AFTER_FAILIRE` observers are invoked and not the `AFTER_SUCCESS`, even though the transaction commits successfully (because the IllegalStateException was caused by not being able to register the synchronisation, and not due to the fact that the transaction failed altogether). I think the error handling should be fixed, because it seems odd that AFTER_FAILIRE observers get invoked for a successful transaction. Furthermore it would be nice to actually support events with transactional observers to be fired from another synchronisation. I am not entirely sure whether it is feasible to support, but I am thinking of an implementation where we just register a synchronisation by default and handle the synchronisation from there, rather than registering the synchronisation on the transaction just in time. Some more background (a stack trace) can be found in the Stackoverflow issue: https://stackoverflow.com/questions/47953827/defer-transactionalobservernotifier-fails-with-arjuna016082-synchronizations-ar |