Skip to content

Exception thrown by TransactionSynchronization#afterCompletion is eaten and there is no way to catch and perform any operation [SPR-12560] #17162

@spring-projects-issues

Description

@spring-projects-issues

Mohammad opened SPR-12560 and commented

Exception thrown in TransactionSynchronization's afterComplete method doesn't be propagated back to calling method. Reason is org.springframework.transaction.support.TransactionSynchronizationUtils class invokeAfterCompletion has below implementation -

public static void invokeAfterCompletion(List<TransactionSynchronization> synchronizations, int completionStatus) {
if (synchronizations != null) {
for (TransactionSynchronization synchronization : synchronizations) {
try {
synchronization.afterCompletion(completionStatus);
}
catch (Throwable tsex) {
logger.error("TransactionSynchronization.afterCompletion threw exception", tsex);
}
}
}
}

Since it is calling multiple synchronizer in a row hence they are eating exception and just logging it(which is clearly written as java doc). I think there should be a way to throw exception so that if required client code can perform some operation.

One solution would be to run afterComplete method in different threads and propagate exceptions with that thread. For programmatic transaction management, we would get know exception (Considering declarative transaction interceptors would not help as control won't come to client code)

Reference question in stackoverflow is - http://stackoverflow.com/questions/27563561/transactionsynchronization-sallow-runtimeexception-that-is-thrown-while-aftercom?noredirect=1#comment43558721_27563561


Affects: 4.0.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: dataIssues in data modules (jdbc, orm, oxm, tx)status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions