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

Using @Retry and @Transactional on the same method #605

Closed
matthiaswelz opened this issue Apr 28, 2022 · 4 comments
Closed

Using @Retry and @Transactional on the same method #605

matthiaswelz opened this issue Apr 28, 2022 · 4 comments

Comments

@matthiaswelz
Copy link

As an application developer I need to be able to use the @Retry annotation in a JTA-enabled application which enables me to provide fault tolerance to transactional methods.

However, this is currently not possible because the specification currently states that:

The base priority of the lowest priority Fault Tolerance interceptor is Priority.PLATFORM_AFTER+10, which is 4010

while the JTA specification states that:

The Transactional interceptors must have a
priority of Interceptor.Priority.PLATFORM_BEFORE+200.

This means that the transactional interceptor will run before the fault tolerance interceptor and all retries will take place in the same transaction. This is an issue for many reasons:

  1. There might be side-effects from a previous attempt attached to the transaction (especially when also using JPA / Hibernate)
  2. The transaction might have timed out already or failed for another reason, so the retry is bound to fail
  3. Deadlock scenarios are possible if the transaction is reused for multiple retries.

The spec should make clear what happens when combining @Retry and @Transactional. One possibility could be introducing another annotation which specifies what happens to the transaction during retries.

Also see: smallrye/smallrye-fault-tolerance#629

@Azquelt
Copy link
Member

Azquelt commented Apr 28, 2022

You can modify the priority of the Fault Tolerance interceptor by setting the mp.fault.tolerance.interceptor.priority config property if you need fault tolerance to be applied at a different point in the interceptor chain.

@matthiaswelz
Copy link
Author

The more I think about, the less I am convinced that just changing the priority would really fix this thoroughly. I think that Retry actually only makes sense in combination with REQUIRES_NEW - otherwise, the retry attempts might still end up sharing the same transaction with all kinds of difficult to diagnose side-effects. So for my use case, I actually want to enforce that Retry is only used with REQUIRES_NEW (because I think that constellation should be “safe”). That’s why I also added the other interceptors which throw an exception when trying to retry a method with TxType.REQUIRED or MANDATORY.

@Ladicek
Copy link
Contributor

Ladicek commented Apr 29, 2022

As I said on the SmallRye Fault Tolerance issue, I haven't been involved in MicroProfile Fault Tolerance since the beginning, but my opinion is that MicroProfile Fault Tolerance was designed chiefly for guarding network interactions and when you try to apply it elsewhere, all kinds of cracks start to appear. I think this is one of those.

@matthiaswelz
Copy link
Author

but my opinion is that MicroProfile Fault Tolerance was designed chiefly for guarding network interactions and when you try to apply it elsewhere, all kinds of cracks start to appear

That is a valid point. Maybe I need to rethink my use-case again.
Thanks again for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants