-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Avoid message listener recovery in case of persistence exceptions from external transaction manager #1807
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
Conversation
If we get an exception, but the transaction completed, log to indicate we rolled back the transaction, but do not re-throw the exception. If the transaction did not complete, then throw the exception as there was likely an infrastructure failure and this listener needs to retry.
} | ||
} | ||
else { | ||
throw ex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be wrapped in an illustrative unchecked exception? As-is, this shouldn't compile because Throwable
is checked, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it should be a syntax error, this is:
public class TestThrowable {
public static void main(String[] args) {
throw new Throwable("Throw me");
}
}
However catching and re-throwing throwable is valid:
public class TestThrowable {
public static void main(String[] args) {
try {
System.out.println("But in a try?");
} catch (Throwable e) {
if (true) {
throw e;
}
}
}
}
Outputs:
But in a try?
Since I don't know what the infrastructure exception is, the only super class is throwable. I don't think I should wrap it in anything in case anything above might handle the original cause and not my wrapper, I was trying to avoid changing anything more behaviour than I had to here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, right, since PlatformTransactionManager.commit(..)
doesn't declare any checked exceptions, the compiler knows that (in this case) Throwable must necessarily be an unchecked exception. If you added something to the try-block that could throw a checked exception, only then throw e;
would fail to compile. Forgot about that nicety; thanks for the patience!
@jhoeller Did you have any further thoughts about this issue and this PR changing the exception handling to throw less infrastructure failure exceptions when the transaction completed with a rollback? |
Revisit this topic, I've arrived at a straightforward change where we can process non-TransactionExceptions from I'll repurpose this PR ticket for the specific purpose suggested but with a custom commit of mine that aligns it with listener exception processing. Thanks for raising the pull request, in any case - and sorry that it took so long to act here. |
Thanks for coming back to this! Hopefully it fixes the problem, I'm no longer working on the project in question so can't test I'm afraid. |
If we get an exception, but the transaction completed, log to indicate
we rolled back the transaction, but do not re-throw the exception.
If the transaction did not complete, then throw the exception as there
was likely an infrastructure failure and this listener needs to retry.