1 Reply Latest reply on Oct 22, 2017 3:30 AM by andey

    Connection being referenced from previous thread/transaction

    rveleda

      Hi there,

       

      We have an application (Hibernate 5.1 + JBoss Seam 2.3.1) currently running on Wildfly 10.1.0.Final. The application relies on a JTA datasource (interleaving=false) that connects to a MySQL database.

       

      Sometimes, on our production environment, we face a IJ031041: Connection handle has been closed and is unusable or IJ031050: The result set is closed under a really specific scenario (e.g. user navigates from one page to another and sends a message). It does not happen everytime and we could barely reproduce it locally.

       

      Here is the context (please see both logs attached):

       

      After enabling the debug option for CCM and verifying the produced logs for the exact moment when this issue happened by using the tracer-report tool, we could notice a strange behaviour regarding the connection use within two transactions.

       

      Transaction 1 happens normally (e.g. user sent a message). However, Transaction 2 (e.g. user is being redirected to another page) fails because it seems to try to use the connection provided on Transaction 1. The ID of the Thread denotes this behaviour.

       

      For some reason, Thread-250 (which was used on Transaction 1), calls returnConnection on Transaction 2. By the time that the application tries to use the connection on Transaction 2, one of the above exceptions is usually thrown. The expected behaviour (noticed on successful transactions) would be for Transaction 2 to keep using its own Thread-287.

       

      At this point we are wondering if this is behaviour is application related. We had the same application running just fine on JBoss-AS-7.1.3.Final though.

       

      Any help would be appreciated. Thanks!

        • 1. Re: Connection being referenced from previous thread/transaction
          andey

          1# Apply the below datasource connection validation:

           

          <validation>

                <validate-on-match>true</validate-on-match>

                <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"></valid-connection-checker>

                <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"></exception-sorter>

          </validation>

           

          2# You should have to set "idle-timeout-minutes" with the appropriate values:

           

          <timeout>

            <idle-timeout-minutes>30</idle-timeout-minutes> <!-- for example, by default 30 minutes-->

          </timeout>

           

          3#Application code must handle exceptions that arise while a connection is held (InUse) by the application component

          Upon completion of connection usage (even if the connection has failed), the application code must explicitly call Connection.close() to return the connection to the pool..

           

          You should close all the opened resources (like Connection, sessions, Statement, ResultSet, PreparedStatement, CallableStatement) properly  in finally block of the individual methods instead of in the try block and close the connection object in the finally block of the parent method.