Bug 54978

Summary: Validate on Borrow should be tested on Reconnect instead of Validate On Connect
Product: Tomcat Modules Reporter: tim.poole
Component: jdbc-poolAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description tim.poole 2013-05-15 19:30:25 UTC
If testOnBorrow is set true, testOnConnect is false, and validationQuery is an illegal query, the current implementation will hide the fact that validationQuery never succeeds.

The offending code is in org.apache.tomcat.jdbc.pool.ConnectionPool line 797.

790            //if we reached here, that means the connection
791	            //is either has another principal, is discarded or validation failed.
792	            //we will make one more attempt
793	            //in order to guarantee that the thread that just acquired
794	            //the connection shouldn't have to poll again.
795	            try {
796	                con.reconnect();
797	                if (con.validate(PooledConnection.VALIDATE_INIT)) {

Instead, con.validate(PooledConnection.VALIDATE_BORROW) should be called.
Comment 1 tim.poole 2013-05-16 13:23:20 UTC
Or better, something akin to con.validate(PooledConnection.VALIDATE_INIT | PooledConnection.VALIDATE_BORROW).
Comment 2 Filip Hanik 2014-08-07 23:16:34 UTC
Thank you for the report, tricky indeed.

Fixed in r1616625