Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
TransactionSynchronizationManager - throw an Exception or log a warning if a Synchronization wants to add a Synchronization and afterCompletion is already called [SPR-11590] #16214
i've got a service A which registered a TransactionSynchronization to do stuff in the afterCommit() case.
After debugging i've found that A did register a Synchronization (doAfterCommit) to call B, and B did also register one (doAfterCompletion).
The one which B registered was never called because doAfterCommit is the last trigger to be called and triggerAfterCompletion was already run.
Maybe a check can be added for addSynchronization(), that it throws an Exception, if the afterCompletion trigger is already reached - or at least a log warning would be nice.
Archie Cobbs commented
This is a more general problem that we have also seen.
Transaction synchronizations are very convenient, so convenient in fact that we've had bugs where code that is running within a synchronization invokes some other code which invokes some other code which itself registers a synchronization. This is a classic programmer "booby trap" that is easy to fall into. The result is that the latter synchronization never runs, because it's too late (the
This problem is exacerbated by the fact that
What's worse is that the failure mode is for the callback to be silently ignored.
This should all be tightened up, both in specification and implementation. In other words, re-entrant synchronization registration behavior is not documented (it should be), and the (undocumented) behavior is sub-optimal (it should be improved).
Juergen Hoeller commented
Someone may use
Could you please tell me why don't use