Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

drewtul
Copy link
Contributor

@drewtul drewtul commented Apr 25, 2018

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.

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.
@drewtul
Copy link
Contributor Author

drewtul commented Apr 25, 2018

@jhoeller Given your thoughts on #1778 I thought this might be a better more generic approach for handling exceptions on transaction manager commit to avoid recycling listeners unless the exception was fatal from the transaction managers perspective i.e. it failed to complete the transaction.

@snicoll snicoll changed the title [SPR-16642] Improve the exception handling around transaction commit. SPR-16642 - Improve the exception handling around transaction commit. May 22, 2018
}
}
else {
throw ex;
Copy link

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?

Copy link
Contributor Author

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.

Copy link

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!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 24, 2019
@drewtul
Copy link
Contributor Author

drewtul commented Mar 4, 2019

@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?

@rstoyanchev rstoyanchev added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Nov 10, 2021
@rstoyanchev rstoyanchev assigned jhoeller and unassigned jhoeller Dec 7, 2021
@rstoyanchev rstoyanchev added this to the Triage Queue milestone Dec 7, 2021
@jhoeller jhoeller added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 18, 2022
@jhoeller jhoeller modified the milestones: Triage Queue, 5.3.16 Jan 18, 2022
@jhoeller jhoeller changed the title SPR-16642 - Improve the exception handling around transaction commit. Avoid message listener recovery in case of persistence exceptions from external transaction manager Jan 18, 2022
@jhoeller
Copy link
Contributor

Revisit this topic, I've arrived at a straightforward change where we can process non-TransactionExceptions from transactionManager.commit as listener exceptions instead of infrastructure exceptions, assuming that they are typically late-triggered persistence exceptions from a listener-used resource (and therefore to be handled like similar exceptions coming out of the listener invocation itself).

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.

@jhoeller jhoeller added in: messaging Issues in messaging modules (jms, messaging) and removed in: data Issues in data modules (jdbc, orm, oxm, tx) labels Jan 18, 2022
@jhoeller jhoeller closed this in 537aced Jan 19, 2022
@drewtul
Copy link
Contributor Author

drewtul commented Jan 19, 2022

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.

@drewtul drewtul deleted the SPR-16642-2 branch January 19, 2022 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants