https://issues.apache.org/bugzilla/show_bug.cgi?id=50571

--- Comment #4 from Jeremy Norris <jnorri...@gmail.com> 2011-01-11 20:52:34 EST 
---
(In reply to comment #3)
>     protected void finalize(PooledConnection con) {
>         JdbcInterceptor handler = con.getHandler();
>         while (handler!=null) {
>             handler.reset(null, null);
>             handler=handler.getNext();
>         }
>     }
> 
> If a reset() throws an exception, the rest of the interceptors wouldn't be
> notified here, and the exception would not mean very much.

Currently, if a connection pool is configured for a database that does not
exist, the first place a SQLException occurs is reset() (with the following
call stack for mysql):

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown
database 'db_name'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    at com.mysql.jdbc.Util.getInstance(Util.java:382)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)
    at com.mysql.jdbc.ConnectionImpl.setCatalog(ConnectionImpl.java:5116)
    at
org.apache.tomcat.jdbc.pool.interceptor.ConnectionState.reset(ConnectionState.java:95)
    at
org.apache.tomcat.jdbc.pool.ConnectionPool.setupConnection(ConnectionPool.java:280)
    at
org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:169)
    at
org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:111)

If reset() swallows and logs this and we don't propagate it, then the upper
layer has no way of acting on this (or controlling the log output).

We can try finishing executing the interceptor stack, ie:

protected void finalize(PooledConnection con) {
    JdbcInterceptor handler = con.getHandler();
    Exception exception = null;
    while (handler!=null) {
        try {
            handler.reset(null, null);
        } catch (SQLException e) {
            exception = e;
        }
        handler=handler.getNext();
    }
    if (exception != null) {
        throw exception
    }
}

but, if more exceptions are thrown from additional interceptors, what exception
should ultimately be thrown from finalize()?

One solution is to NOT continue processing the interceptor stack.  If
interceptors need to be notified, we could use another event.

Thoughts?

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to