Issue Details (XML | Word | Printable)

Key: DBCP-237
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Oliver Matz
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Commons Dbcp

InstanceKeyDataSource.getConnection, exception during setup Defaults()

Created: 20/Aug/07 11:20 AM   Updated: 25/Mar/08 08:11 AM
Return to search
Component/s: None
Affects Version/s: 1.2.1, 1.2.2
Fix Version/s: 1.3

Time Tracking:
Not Specified

Environment: Sybase jConnect2 5.5, spring framework 2.0.1

Resolution Date: 04/Feb/08 04:00 AM


 Description  « Hide
Problem in
org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getConnection(String username, String password)
if setupDefaults() throws an Exception, the connection will not get closed.
After a while, this will cause the following exception:
org.apache.commons.dbcp.SQLNestedException: Could not retrieve connection info from pool

This scenario can happen for Sybase jConnect2 5.5. The exception that may be thrown by jConnect2 is:
com.sybase.jdbc2.jdbc.SybConnectionDeadException: JZ0C0: Connection is already closed.

More details:
The last lines of the method are as follows:
-------
Connection con = info.getPooledConnection().getConnection();
setupDefaults(con, username);
con.clearWarnings();
return con;
-------

In my case, the exception happens in the second line of this snippet,
so no code gets the chance close con and release the resources.

I propose to change it to:

-------
Connection con = info.getPooledConnection().getConnection();
try
{
setupDefaults(con, username);
con.clearWarnings();
return con;
}
catch (Exception exc)
{
try

{ con.close(); }

catch (Exception exc)

{ getLogWriter().println("ignoring exception during close: " + exc); // uncertain here. }

throw exc;
}



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #618163 Mon Feb 04 03:58:08 UTC 2008 psteitz Added exception handler to ensure that PooledConnections are not orphaned
when an exception occurs in setUpDefaults or clearWarnings in
IntanceKeyDataSource getConnection.

JIRA: DBCP-237
Reported and patched by Oliver Matz
Files Changed
MODIFY /commons/proper/dbcp/trunk/pom.xml
MODIFY /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/InstanceKeyDataSource.java
ADD /commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestInstanceKeyDataSource.java
MODIFY /commons/proper/dbcp/trunk/xdocs/changes.xml
MODIFY /commons/proper/dbcp/trunk/project.xml