spring-projects / spring-projects/spring-modulith
DefaultEventPublicationRegistry markCompleted method's REQUIRES_NEW transaction propagation means events are marked completed before handler transactions are committed.
@odrotbohm is already working on this.
Since Jan 30, 2024.
- Dominant language
- Java
- Stars
- 1.2k
- Forks
- 222
- PR merge metrics
- No merged PRs in 30d
Description
The markCompleted method of DefaultEventPublicationRegistry is invoked in a MethodInterceptor defined in CompletionRegisteringAdvisor, which intercepts the event handler method, invokes it, then calls the EventPublicationRegistry's markCompleted method to mark the eventPublication as complete.
Because of the REQUIRES_NEW transaction propagation type, markCompleted runs with a completely distinct database connection, and independent transaction from the event handler's transaction. This means there's a chance the event handler's transaction can commit, but the markCompleted transaction does not, which leaves the eventPublication appearing incomplete in the database even though it was completely successfully handled.
I propose that markCompleted should have the REQUIRED transaction propagation type. I believe this should cause markCompleted to commit the eventPublication as completed in the same transaction as the event handler.
Let me know what you think, I can submit a PR.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.