Bug 34896 - Connection Leak in TransactionTagSupport
Summary: Connection Leak in TransactionTagSupport
Status: RESOLVED FIXED
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: 1.0.6
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-12 15:42 UTC by Andrew Craft
Modified: 2007-07-22 17:55 UTC (History)
0 users



Attachments
Fix (914 bytes, patch)
2007-02-07 20:58 UTC, Henri Yandell
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Craft 2005-05-12 15:42:45 UTC
When wrapping connections in a Transaction tag like:
<sql:transaction dataSource="JNDI.DS">
<sql:query var="query1" >
SELECT * from etc
</sql:query>
<sql:query var="query2" >
SELECT * from etc
</sql:query>
</sql:transaction>

The transaction tag causes a connection leak, the reason is as follows

The nested connection correctly uses the parent connection object. The 
TransactionTagSupport class tries to close the connection in the doFinally() 
method, the problem is before the doFinally() tag is called the release() 
method is called which calls init() which sets the connection object to null 
and hence the doFinally() is unable to close the connection as there is no 
longer a reference to the object and hence the leak.

Proposal would be to remove the init() method from the release() method.

Environment:
Weblogic 8.1 sp3
datasource is sybase looked up by jndi reference.

class:
org.apache.taglibs.standard.tag.common.sql.TransactionTagSupport
Comment 1 Henri Yandell 2007-01-31 13:46:42 UTC
Looking at the code, I think a simpler approach would be to remove the conn =
null; from init(). It's unnecessary as doFinally takes care of that.
Comment 2 Bjorn Townsend 2007-02-07 18:35:10 UTC
FYI - I tried to reproduce this with Tomcat 5.5.20 and mysql using the jdbc
connector, and failed -- behavior was as expected. This must be pretty specific
to the JNDI driver, and I don't have a Sybase DB to test with. I did try
preventing garbage collection on the connection, to no avail.
Comment 3 Henri Yandell 2007-02-07 20:58:59 UTC
Created attachment 19543 [details]
Fix

Attached fix. From inspection, it's definitely a problem. 

The init() method is only called by the constructor and release(), so I've
deleted the init() method. All of its statements are in the constructor, and
two are then added to the release.

There is also a bug concerning the isolation once the Connection bug is fixed.
It won't get set back to the origIsolation but will always become
TRANSACTION_NONE. So I've fixed that by adding it to the doFinally() rather
than the release().
Comment 4 Henri Yandell 2007-02-07 21:01:02 UTC
Applying fix:

svn ci -m "Applying fix from 34896" src/

Sending       
src/org/apache/taglibs/standard/tag/common/sql/TransactionTagSupport.java
Transmitting file data .
Committed revision 504780.

Need to make sure nothing has been broken in the standard-examples (or in your
attempted reproduction Bjorn?) before closing as FIXED.
Comment 5 Bjorn Townsend 2007-02-08 12:59:34 UTC
Henri, your fix does not change the behavior of my attempted repro, so I don't
think it broke anything. :)