GeoTools
  1. GeoTools
  2. GEOT-1698

no check of connection validity on ConnectionPool

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0
    • Fix Version/s: 2.2.3
    • Component/s: jdbc
    • Labels:
      None
    • Environment:
      All

      Description

      There's no check when returning an available connection from a Pool if that connection is valid yet.
      The method getConnection on ConnectionPool check only if there is an available connection in the pool, but doesn't check if that connection is valid.

      We work with a timeout on connections and Oracle may close sessions after some minutes if they are not used. So we obtain exception when trying to use that connections.

      In the class ManagedPooledConnection there is the isValid() method that is not called from PoolConnection, but also if it did the isValid() method check the connection trying to close it.
      I think it would be better to create a method that check validity of connection calling a rollback() on it. That method could be called from the getConnection method of ConnectioPool before returning the connection. If the connection is not valid anymore, it should create a new connection.

      I think this issue is also on later versions!

        Issue Links

          Activity

          Hide
          Andrea Aime added a comment -
          Federico, this issue has been fixed in 2.4.0 by removing the whole connection pooling subsystem and using DBCP instead. DBCP can be configured to validate connections.
          Show
          Andrea Aime added a comment - Federico, this issue has been fixed in 2.4.0 by removing the whole connection pooling subsystem and using DBCP instead. DBCP can be configured to validate connections.
          Hide
          Andrea Aime added a comment -
          All gt2 series besides 2.4.x and trunk are not actively mantained anymore. For sure there won't be any more 2.1.x releases.
          gt2 2.2.x is still used by uDig, but should be dropped soon. So, I guess it's up to the uDig developers to decide wheter to act on this one or not.
          Show
          Andrea Aime added a comment - All gt2 series besides 2.4.x and trunk are not actively mantained anymore. For sure there won't be any more 2.1.x releases. gt2 2.2.x is still used by uDig, but should be dropped soon. So, I guess it's up to the uDig developers to decide wheter to act on this one or not.
          Hide
          Jody Garnett added a comment -
          Thanks for the patch; I have used it to fix the 2.2.x code - your fix will be avaialble when 2.2.3 goes out.
          - fixed isValid to use rollback() rather than close. Usually we test with select 1 but life is short
          - ConnectionPool now does the following

          {code}
          if( !mConn.isValid() ){
              LOGGER.warning("Connection is not valid anymore. It's necessary create a new Connection.");
              PooledConnection pConn = cpDataSource.getPooledConnection();
              conn = pConn.getConnection();
              pConn.addConnectionEventListener(listManager);
              mConn = new ManagedPooledConnection(pConn);
          }
          {code}

          Thanks!
          Show
          Jody Garnett added a comment - Thanks for the patch; I have used it to fix the 2.2.x code - your fix will be avaialble when 2.2.3 goes out. - fixed isValid to use rollback() rather than close. Usually we test with select 1 but life is short - ConnectionPool now does the following {code} if( !mConn.isValid() ){     LOGGER.warning("Connection is not valid anymore. It's necessary create a new Connection.");     PooledConnection pConn = cpDataSource.getPooledConnection();     conn = pConn.getConnection();     pConn.addConnectionEventListener(listManager);     mConn = new ManagedPooledConnection(pConn); } {code} Thanks!
          Hide
          Jody Garnett added a comment -
          Patch rolled back out of 2.2.x as the isValid check for postgis seems not to work (see UDIG-1380 for example strack trace).
          Show
          Jody Garnett added a comment - Patch rolled back out of 2.2.x as the isValid check for postgis seems not to work (see UDIG-1380 for example strack trace).

            People

            • Assignee:
              Jody Garnett
              Reporter:
              Federico Nieri
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: