Skip to content

Rollback without transaction with propagation SUPPORTS causes a warn-level log entry [SPR-1749] #6446

@spring-projects-issues

Description

@spring-projects-issues

Erwin Bolwidt opened SPR-1749 and commented

When a 'transaction' is rolled back (method processRollback in AbstractPlatformTransactionManager), in the testcase as a result of an exception in an intercepted class, a log entry is logged at level 'warn' with the message "[12:54:46,750 438 ,DataSourceTransactionManager] Should roll back transaction but cannot - no transaction available".

The transaction properties of the interceptor are defined as "PROPAGATION_SUPPORTS,-Exception". The problem also occurs with "PROPAGATION_NEVER,-Exception", which is in itself an illogical definition but allowed by spring.

The problem is that a transaction doesn't have to be present in the intercepted code - that's why PROPAGATION_SUPPORTS was used - and warn level log entries cause alarm bells to go off in the production environment. I think that a 'rollback' on a spring transaction that doesn't have a real transaction behind it - the implementation used for SUPPORTS - should not cause this warning because this is what is expected.

I can think of the following solutions:

1 - don't log the warning at all in AbstractPlatformTransactionManager
2 - pass a TransactionDefinition into the rollback method of AbstractPlatformTransactionManager so processRollback can decide to log dependent on the propagation behaviour
3 - let the TransactionAspectSupport class decide whether to call rollback or not dependent on the propagation behaviour and whether there is an actual transaction.

I think that 3 is easier to implement, but 2 is cleaner. However 1 is easiest and I don't see a big issue with it either.

One way to implement 3 is to patch the doCloseTransactionAfterThrowing method of TransactionAspectSupport, and replace the line

this.transactionManager.rollback(txInfo.getTransactionStatus());

with the code

int propagation = txInfo.getTransactionAttribute().getPropagationBehavior();
DefaultTransactionStatus txStatus = (DefaultTransactionStatus) txInfo.getTransactionStatus();
if (propagation == TransactionDefinition.PROPAGATION_MANDATORY ||
    propagation == TransactionDefinition.PROPAGATION_REQUIRED ||
    propagation == TransactionDefinition.PROPAGATION_REQUIRES_NEW || 
    txStatus.hasTransaction()) { 
    this.transactionManager.rollback(txInfo.getTransactionStatus());
}

Affects: 1.2.6

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions