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

Daniel Mikusa <dmik...@vmware.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #30045|0                           |1
        is obsolete|                            |
  Attachment #30086|0                           |1
        is obsolete|                            |

--- Comment #6 from Daniel Mikusa <dmik...@vmware.com> ---
Created attachment 30094
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=30094&action=edit
Third patch

Ok, so there was an issue with my second patch.  When "testOnConnect" was
enabled, the validation query specified times out and a connection was
requested, an NPE would be thrown from "setupConnection", where
"con.getHandler()" is called.

    protected Connection setupConnection(PooledConnection con) throws
SQLException {
        //fetch previously cached interceptor proxy - one per connection
        JdbcInterceptor handler = con.getHandler();
        if (handler==null) {

This was because "borrowConnection", at the point below, returns null.

    public Connection getConnection() throws SQLException {
        //check out a connection
        PooledConnection con = borrowConnection(-1,null,null);
        return setupConnection(con);
    }

It returned null because of the following conditions...

  - there are no available connections
  - "borrowConnection(..)" tries to create one by calling
"createConnection(..)"
  - because "testOnConnect" is true, "createConnection(..)" will call
"con.validate(..)" and the validation query will run
  - because we use a slow query and set a low validation query timeout, the
validation query is interrupted
  - "con.validate(..)" returns false
  - this causes "createConnection(..)" to clean up and return null
  - "borrowConnection(..)" returns what was returned by "createConnection(..)",
which is null
  - the null then slips through to "setupConnection(con)" and causes the NPE.

I fixed this by throwing an SQLException in "createConnection(..)" when
"con.validate(..)" returns false.  This causes "createConnection(..)" to clean
up and then re-throw the SQLException.  This exception bubbles up to the user's
code alerting them that the pool cannot create any new connections because the
validation query fails.

A very similar situation happens if the validation query is invalid, such as
"SELECT".  This fixes both conditions.  Unit tests included in the latest
patch.

-- 
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