spring-projects / spring-projects/spring-modulith

DefaultEventPublicationRegistry markCompleted method's REQUIRES_NEW transaction propagation means events are marked completed before handler transactions are committed.

Open
#485 4 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Jan 30, 2024.

meta: waiting for feedback
Dominant language
Java
Stars
1.2k
Forks
222
PR merge metrics
No merged PRs in 30d

Description

https://github.com/spring-projects/spring-modulith/blob/c5f73e675d74c7a40d68957ca56be35d4d2c8ea3/spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/core/DefaultEventPublicationRegistry.java#L104-L105

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.