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

JDBI 3 - Handle.close() throws Failed to clear transaction status on close error #2065

Closed
lohitpradhan opened this issue Jul 17, 2022 · 4 comments · Fixed by #2068
Closed

Comments

@lohitpradhan
Copy link

lohitpradhan commented Jul 17, 2022

We use jdbi api in our drop wizard based application which internally uses tomcat connection pool for db operations.
Below code snippet is used to delete user from our oracle database.

jdbi.useHandle(
 handle ->
 handle.createUpdate("DROP USER XXXXX CASCADE")
 .execute());

The above code throws an error -

Caused by: org.jdbi.v3.core.CloseException: Failed to clear transaction status on close
at org.jdbi.v3.core.Handle.close(Handle.java:183)
at org.jdbi.v3.core.Jdbi.withHandle(Jdbi.java:358)
at org.jdbi.v3.core.Jdbi.useHandle(Jdbi.java:373)
at com.test.db.DBSchemaProviderImpl.deleteDBSchema(DBSchemaProviderImpl.java:57)
... 7 common frames omitted
Caused by: org.jdbi.v3.core.transaction.TransactionException: Failed to test for transaction status
at org.jdbi.v3.core.transaction.LocalTransactionHandler$BoundLocalTransactionHandler.isInTransaction(LocalTransactionHandler.java:194)
at org.jdbi.v3.core.Handle.isInTransaction(Handle.java:346)
at org.jdbi.v3.core.Handle.close(Handle.java:154)
... 10 common frames omitted
Caused by: java.sql.SQLException: Connection has already been closed.
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:121)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
at org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.invoke(AbstractCreateStatementInterceptor.java:79)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:81)
at com.sun.proxy.$Proxy110.getAutoCommit(Unknown Source)
at org.jdbi.v3.core.transaction.LocalTransactionHandler$BoundLocalTransactionHandler.isInTransaction(LocalTransactionHandler.java:192)
... 12 common frames omitted

Please suggest a way of working with this code. Thanks

@hgschmie
Copy link
Contributor

Hi @lohitpradhan,

Thank you for filing an issue with the JDBI project. We appreciate any feedback! To be able to investigate this further, please provide

  • version of JDBI that you are using
  • version of the tomcat pool library
  • version of the oracle driver
  • any settings that you have within the connection pool or the driver

It is very difficult for us to investigate any problems if we do not know what setup and versions you are using.

@lohitpradhan
Copy link
Author

lohitpradhan commented Jul 18, 2022

version of JDBI that you are using : v3

 <dependency>
      <groupId>io.dropwizard</groupId>
      <artifactId>dropwizard-jdbi3</artifactId>
      <version>2.0.29</version>
    </dependency>

version of the tomcat pool library:

<dependency>
     <groupId>io.dropwizard</groupId>
     <artifactId>dropwizard-db</artifactId>
     <version>2.0.29</version>
   </dependency>

version of the oracle driver :

 <dependency>
      <artifactId>ojdbc8</artifactId>
      <groupId>com.oracle.database.jdbc</groupId>
      <version>21.3.0.0</version>
    </dependency>

any settings that you have within the tomcat connection pool or the driver:

        validationQueryString: "SELECT 1 from dual"
        validationQueryTimeout: 10s
        initialSize: 5
        minSize: 5
        maxSize: 10
        removeAbandoned : true
        removeAbandonedTimeout : 1m
        maxConnectionAge: 30m
        maxWaitForConnection: 300s
        checkConnectionOnBorrow: true

hgschmie added a commit to hgschmie/jdbi that referenced this issue Jul 18, 2022
Ensure that the handle will tolerate a closed connection when close()
is called. If the database connection gets closed between the last
operation finishing successfully and the handle being closed, checking
the autocommit status will cause an exception to be thrown that is
user-visible but not actionable. Check the connection state before
executing any operation on the database connection.

Fixes jdbi#2065
hgschmie added a commit that referenced this issue Jul 19, 2022
Check connection status in handle.close()

Ensure that the handle will tolerate a closed connection when close()
is called. If the database connection gets closed between the last
operation finishing successfully and the handle being closed, checking
the autocommit status will cause an exception to be thrown that is
user-visible but not actionable. Check the connection state before
executing any operation on the database connection.

Fixes #2065
@lohitpradhan
Copy link
Author

Thanks for this change, it really helps a lot. can you please let me know the release version which has this change ?

@lohitpradhan
Copy link
Author

@hgschmie may i know how to uptake these changes or which version should i use ?

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

Successfully merging a pull request may close this issue.

2 participants