Exception thrown from CorrelationDataProvider breaks transaction management


I’m not sure this can be considered a bug in Axon Framework 4.5.8 but I think it is something users should be made aware of by the documentation.

I recently learned the hard way that CorrelationDataProviders are a critical section of the UnitOfWork life-cycle because they are called during exception handling, more specifically when constructing the result message, right before handling rollback.

See this excerpt from the DefaultUnitOfWork class:

try {
    result = task.call();
} catch (Error | Exception e) {
    resultMessage = asResultMessage(e); // <-- Correlation data providers are called here
    if (rollbackConfiguration.rollBackOn(e)) {  // If an exception was thrown on the line before, rollback is not performed which leaves the transaction in a broken state.
        return resultMessage;

As I said above, I’m not sure there’s an obvious way to handle this problem, but I believe the documentation should make it obvious that exception thrown from a CorrelationDataProvider is a no-no.

Thanks for raising this concern with us, @svolle.
Although chances are typically slim the CorrelationDataProvider throws an exception, the chance is still there, as you’ve noticed.

I think it wouldn’t hurt if Axon Framework would find a way to catch exceptions on that level to at the very least invoke the rollback method.
Would you mind drafting up an issue for this on AF’s GitHub, perhaps?