Skip to content
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

@TransactionalEventListener should not receive an event if no transaction is active #23276

Closed
clembo590 opened this issue Jul 11, 2019 · 3 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@clembo590
Copy link

clembo590 commented Jul 11, 2019

when a component method is annotated with @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT), no event should be received from a code block annotated with @Transactional(propagation = Propagation.NOT_SUPPORTED)

I made a very small spring boot project that shows the issue:
2 Test methods in that project:

@Test public void notTransactional() --> WORKS OK (no transactional event is received)
@Test public void notSupported() --> (KO: an event is received and it should not be because the block from witch the event is send is a propagation=NOT_SUPPORTED block)

com.cbo.transac.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 11, 2019
@snicoll
Copy link
Member

snicoll commented Jul 11, 2019

Thanks for the sample, that is very helpful. I believe there is a faulty check in ApplicationListenerMethodTransactionalAdapter that relies on TransactionSynchronizationManager.isSynchronizationActive() to figure out if the current thread is running within a transaction. In the case of a NOT_SUPPORTED propagation type, this returns true so we should probably look at something else to drop the event.

@snicoll snicoll added type: bug A general bug status: waiting-for-triage An issue we've not yet triaged or decided on and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 11, 2019
@snicoll
Copy link
Member

snicoll commented Jul 11, 2019

@jhoeller wondering what our backport strategy for this one should be. Can be potentially annoying if users were relying on that side effect so I am tempted to fix this in 5.2 only. Thoughts?

@snicoll snicoll changed the title @TransactionalEventListener issue @TransactionalEventListener should not receive an event if no transaction is active Jul 12, 2019
@snicoll snicoll removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 12, 2019
@snicoll snicoll self-assigned this Jul 12, 2019
@snicoll snicoll added this to the 5.2 RC1 milestone Jul 12, 2019
@snicoll
Copy link
Member

snicoll commented Jul 12, 2019

Alright, chatting with @jhoeller we discovered that SUPPORTS propagation type without an actual transaction triggers the event. It is likely that users may have relied on that faulty behaviour so let's fix that behaviour and clarify the Javadoc to specifically mention the fact an actual transaction is required.

snicoll added a commit that referenced this issue Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants