-
Notifications
You must be signed in to change notification settings - Fork 38k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TransactionSynchronizationManager - throw an Exception or log a warning if a Synchronization wants to add a Synchronization and afterCompletion is already called [SPR-11590] #16214
Comments
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). My recommendation:
|
Juergen Hoeller commented
|
@jhoeller Someone may use Could you please tell me why don't use Thanks. |
Torsten Krah opened SPR-11590 and commented
Hi,
i've got a service A which registered a TransactionSynchronization to do stuff in the afterCommit() case.
It calls a service B to index things to lucene.
I've forgot that i did already leveraged the transaction handling to the lucene service B, so i did wonder why nothing happened and no error was thrown.
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.
Affects: 4.0.2
Issue Links:
The text was updated successfully, but these errors were encountered: