Subject Help locate a connection leak...
Author skullmaggots

I have an application that just recently after a deployment of a new
version started to open more connections to the database server than
before, so we suspected a connection leak where a connection obtained
from the pool (via FBWrappingDataSource) was not being returned or
could not be reused for some reason.

In order to tack down the problem I have written some AOP code to
count connections opens, resources obtained on those connections e.g.
Statements, ResultSet and record the classes responsible. This report
shows some potential errors e.g. Not closing ResultSets, or Statements
is some classes.

But I need to understand the type of error that would really cause a
leak so I have the following questions, note:- I'm using a FBWrapping

1) If Statements, PrepareStatements, or CallableStatements were not
closed but the connection they were obtained using were would this
cause an issue?

2) Is the order of closing resources important.
For example I have found code that closed Statements, before Closing
the ResultSets obtained via the Statements, would this cause any

3) Again if a ResultSet wasn't closed but the connection was, is this
a problem?

I know the theory that all resources should be closed as this is good
manners but I'm faced with a large amount of code I didn't write so I
have to be clear as to what in pratice will 'actually' cause the
connection pool to keep opening more connections than it should.

This leak appears to be rather slow, so it's only after a days
intensive usage that the pool will have opened 90 connections where as
before the new deployment it would open 30.

Also if I stop access to the site and then wait says 10 mins (ldle
time=1 min, min connections=0) I would expect under normal
circumstances for all the database connections to close, is this

What I have observed is that for 130 connections open, only 18 are
closed after waiting 10 mins with no site activity, does this mean 112
(130-18) connections have leaked?


Jeff Bannister.