Skip to content

Suppress "Unable to rollback against JDBC Connection" in case of timeout (connection closed) #34714

Closed
@phildeg31

Description

@phildeg31

Hi,
I use Spring Boot 3.4.4 with an Oracle database (JpaTransactionManager, JpaRepository and Hikari connection are used).

I set a timeout on @transactional to stop the treatment of the service if it is too long (due to long database queries according to parameters) like this:
@Transactional(readOnly = true, timeout = 40)

If the timeout is reached for the transaction, then I expect to have an exception related to this reason thrown by JPA transaction manager (ex: JPATimeoutException) but I have the following exception with no link to the timeout:

org.springframework.orm.jpa.JpaSystemException: Unable to rollback against JDBC Connection
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:341)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:241)
at org.springframework.orm.jpa.JpaTransactionManager.doRollback(JpaTransactionManager.java:593)
...
Caused by: org.hibernate.TransactionException: Unable to rollback against JDBC Connection
at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.rollback(AbstractLogicalConnectionImplementor.java:137)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.rollback(JdbcResourceLocalTransactionCoordinatorImpl.java:289)
at org.hibernate.engine.transaction.internal.TransactionImpl.rollback(TransactionImpl.java:142)
...
Caused by: java.sql.SQLException: Connection is closed
at com.zaxxer.hikari.pool.ProxyConnection$ClosedConnection.lambda$getClosedConnection$0(ProxyConnection.java:503)
at jdk.proxy3/jdk.proxy3.$Proxy144.rollback(Unknown Source)
at com.zaxxer.hikari.pool.ProxyConnection.rollback(ProxyConnection.java:386)
at com.zaxxer.hikari.pool.HikariProxyConnection.rollback(HikariProxyConnection.java)

If I check logs, I see that a cancel of the query has been asked (because of the timeout if I understand):
ORA-01013: user requested cancel of current operation
Then, I see a log indicating that the transaction is converted into a rollback exception:
ERROR o.s.t.i.TransactionInterceptor - Application exception overridden by rollback exception
Also, it seems that the connection is closed after the cancel.

The rollback exception provokes a rollback in HikariProxyConnection that cannot be done because the connection has been closed.

If I catch the exception thrown by the service (on which I have @transactional with timeout), I have the JpaSystemException with a root cause indicating that that the connection is closed (see the stacktrace above). The information about the timeout reached is lost and I am not able to identify that I had a timeout (as a "Caused by" at least).

Is it possible to keep at least the root cause (=the timeout was reached) because here it is strange to have nothing related to it?

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions