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

NoRollbackFor rule causes TransactionAspectSupport to log unwarranted "exception overridden" error on WebSphere #25253

Closed
fralalonde opened this issue Jun 15, 2020 · 2 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@fralalonde
Copy link

fralalonde commented Jun 15, 2020

Observed using Spring 4.3.26, expecting same behavior from Spring 5.x after code comparison.

The application code throws custom NoDataFoundException checked exception in normal conditions to report absence of data, which is then handled outside the transaction. Certainly not the best pattern, but unsolvable for now due to a myriad of possible side effects.

To alleviate the issue, we're using NoRollbackRule attribute in the form of +NoDataFoundException on TransactionProxyFactoryBean like so:

<bean id="MyBean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionAttributes">
        <props>
            <property key="method1">PROPAGATION_REQUIRED,+NoDataFoundException</prop>

This results in NoDataFoundException being correctly rethrown outside tx, but still emitting an error log statement like so:

org.springframework.transaction.interceptor.TransactionAspectSupport invokeWithinTransaction Application exception overridden by commit exception
                                 <com.app.NoDataFoundException>

Stepping into invokeWithinTransaction code, it appears that the checked exception being rethrown is mistaken as a "new" transaction commit exception, overriding... itself.

Initial capture of the checked exception:

if (txAttr.rollbackOn(ex)) {
 [...]
}
else {
	// A normal return value: will lead to a commit.
	throwableHolder.throwable = ex;
	return null;
}

Rethrowing outside of tx:

// Check result state: It might indicate a Throwable to rethrow.
if (throwableHolder.throwable != null) {
	throw throwableHolder.throwable;
}

Exception re-handled on exit, triggering extraneous logging:

catch (Throwable ex2) {
	if (throwableHolder.throwable != null) {
		logger.error("Application exception overridden by commit exception", throwableHolder.throwable);
	}
	throw ex2;
}

Fixing this situation should be as simple as comparing ex2 and throwableHolder.throwable for equality (in addition to the null check already in place), or resetting throwableHolder.throwable to null upon rethrowing the checked exception. A PR can be submitted to this effect if requested.

A quick workaround would be to disable logging for the TransactionProxyFactoryBean, which is unpalatable because of the many other serious error conditions that could go unreported. A more sophisticated patch would apply a targeted logging filter to ignore error entries mentioning the checked exception class.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 15, 2020
@jhoeller jhoeller self-assigned this Jun 16, 2020
@jhoeller jhoeller added in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 16, 2020
@jhoeller jhoeller added this to the 5.2.8 milestone Jun 16, 2020
@jhoeller
Copy link
Contributor

I suppose you're running on WebSphere since this only seems to affect the CallbackPreferringPlatformTransactionManager code path (with WebSphereUowTransactionManager being the only common implementation of that variant)?

In any case, it is indeed falling over its own feet in the exception handling code path there, that log statement needs to be avoided. We'll also backport this to 5.1.x, 5.0.x and 4.3.x once resolved here.

@fralalonde
Copy link
Author

Yes, this is on WebSphere.

@jhoeller jhoeller changed the title NoRollbackFor rule causes TransactionAspectSupport to log unwarranted "exception overridden" error NoRollbackFor rule causes TransactionAspectSupport to log unwarranted "exception overridden" error on WebSphere Jun 17, 2020
@jhoeller jhoeller added the for: backport-to-5.1.x Marks an issue as a candidate for backport to 5.1.x label Jun 17, 2020
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.1.x Marks an issue as a candidate for backport to 5.1.x labels Jun 17, 2020
FelixFly pushed a commit to FelixFly/spring-framework that referenced this issue Aug 16, 2020
zx20110729 pushed a commit to zx20110729/spring-framework that referenced this issue Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants