tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: [jdbc-pool] Transaction left open by the connection validation mechanism ?
Date Fri, 04 Jan 2013 21:38:21 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Pid,

On 1/4/13 4:26 PM, Pid wrote:
> On 04/01/2013 20:34, Christopher Schultz wrote:
>> On 1/3/13 12:49 PM, Davoust, Pascal wrote:
>>> 
>>> I then had a look at the corresponding code into the tomcat
>>> jdbc pool (source 7.0.34), and more specifically in class 
>>> org.apache.tomcat.jdbc.pool.PooledConnection, method public 
>>> boolean validate(int validateAction,String sql) at line 452 
>>> (excerpt below):
>> 
>>> Statement stmt = null; try { stmt =
>>> connection.createStatement(); stmt.execute(query);
>>> stmt.close(); this.lastValidated = now; return true; } catch
>>> (Exception ex) { if 
>>> (getPoolProperties().getLogValidationErrors()) { log.warn("SQL 
>>> Validation error", ex); } else if (log.isDebugEnabled()) { 
>>> log.debug("Unable to validate object:",ex); } if (stmt!=null)
>>> try { stmt.close();} catch (Exception ignore2){/*NOOP*/} }
>>> return false;
>> 
>> You (may) have a resource leak: you are not closing your
>> statement in the case of an exception. You need a 'finally'
>> block.
> 
> I think Pascal is saying that the above snippet is in the Tomcat
> JDBC code, not his.

Whoops, I think you're right. That's a minor bug, but definitely one
that should be fixed IMO.

Also, if the validation query succeeds and the connection is in
auto-commit mode, we may want to issue a rollback. I wouldn't want to
do that without any additional configuration, though, because it would
needlessly send ROLLBACK queries in many cases (such as other
databases - MySQL doesn't get upset when I tried a simple, similar
test - or when you don't intend to change the transaction isolation
level, etc.).

Perhaps a configuration directive like rollBackAfterValidationQuery or
something?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with undefined - http://www.enigmail.net/

iEYEAREIAAYFAlDnS80ACgkQ9CaO5/Lv0PCCYQCguRp0qAPS/ViLhUKGyV+Tc6mY
2qMAn3DpYdxDl5zo9EgLpqDSIFPmCDrD
=U427
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message