Hello guys, we have migrated to Tomcat DBCP 8.0.18 from 7.0.37 recently and
faced the following issue:
after database restart (Postgres), our application wasn't been able to
restore connectivity to DB, all connections were closed and every time,
after failed attempt to execute some SQL statement, returned back to pool.
Pool is configured with all tests (on borrow, on return, on connect, while
idle) disabled. Pool configuration is the same for 8.0.18 and 7.0.37.
While using 7.0.37 DBCP is able to restore from DB restart, because
PoolableConnection class performs explicit check if underlying SQL
connection is closed:

     public synchronized void close() throws SQLException {
        if (_closed) {
            // already closed
            return;
        }

        boolean isUnderlyingConectionClosed;
        try {
            isUnderlyingConectionClosed = _conn.isClosed();
        } catch (SQLException e) {
            try {
                _pool.invalidateObject(this); // XXX should be guarded to
happen at most once
            } catch(IllegalStateException ise) {
                // pool is closed, so close the connection
                passivate();
                getInnermostDelegate().close();
            } catch (Exception ie) {
                // DO NOTHING the original exception will be rethrown
            }
            throw (SQLException) new SQLException("Cannot close connection
(isClosed check failed)").initCause(e);
        }
       ...

My question is: why this check was removed and how can one get the same
behaviour (of 7.0.37) using 8.0.18 (not using on borrow, on return, while
idle validations, which are SQL queries)? I see that there is a property in
pool configuration which allows user to provide custom Validator, though I
don't want to go this way because DBCP configuration is performed by 3rd
party library and we don't have direct access to it.

Reply via email to