Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 1946B9FB1F3 for ; Sun, 22 Jul 2007 05:04:18 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 42503-04 for ; Sun, 22 Jul 2007 05:04:11 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from gw03.mail.saunalahti.fi (gw03.mail.saunalahti.fi [195.197.172.111]) by postgresql.org (Postfix) with ESMTP id BE78E9FA303 for ; Sun, 22 Jul 2007 05:04:14 -0300 (ADT) Received: from [10.0.0.4] (a88-113-10-143.elisa-laajakaista.fi [88.113.10.143]) (using SSLv3 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by gw03.mail.saunalahti.fi (Postfix) with ESMTP id A1AAF21611A; Sun, 22 Jul 2007 11:04:11 +0300 (EEST) Subject: Re: Fix more unit test connection leaks From: Mikko Tiihonen To: Kris Jurka Cc: pgsql-jdbc In-Reply-To: References: <1185062569.1632.80.camel@dual.local> Content-Type: text/plain Date: Sun, 22 Jul 2007 11:04:11 +0300 Message-Id: <1185091451.1632.91.camel@dual.local> Mime-Version: 1.0 X-Mailer: Evolution 2.10.2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/102 X-Sequence-Number: 17276 On Sat, 2007-07-21 at 21:31 -0400, Kris Jurka wrote: > > On Sun, 22 Jul 2007, Mikko Tiihonen wrote: > > > I found some more connection leaks from the test cases. > > > > Yeah, I started looking at your original patch and figured there would be > more, so I enabled the code to report the location of any opened but > unclosed connections (in the attached hack). Does your latest patch pass > this test? Unfortunately it did not. My previous try at ConnectionPoolTest leaks were unsuccessfull due to the working connection wrapper that the pool uses. With this final (third) connection leak patch the unit tests no longer complain about leaked connections. Index: org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java,v retrieving revision 1.15 diff -u -r1.15 ConnectionPoolTest.java --- org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java 11 Jan 2005 08:25:48 -0000 1.15 +++ org/postgresql/test/jdbc2/optional/ConnectionPoolTest.java 22 Jul 2007 07:56:10 -0000 @@ -14,6 +14,7 @@ import org.postgresql.test.TestUtil; import javax.sql.*; import java.sql.*; +import java.util.*; import java.io.*; /** @@ -25,6 +26,8 @@ */ public class ConnectionPoolTest extends BaseDataSourceTest { + private ArrayList connections = new ArrayList(); + /** * Constructor required by JUnit */ @@ -48,6 +51,19 @@ bds.setPassword(TestUtil.getPassword()); } } + + protected void tearDown() throws Exception + { + for (Iterator i = connections.iterator(); i.hasNext(); ) { + PooledConnection c = (PooledConnection) i.next(); + try { + c.close(); + } catch (Exception ex) { + // close throws nullptr or other evil things if the connection + // is already closed + } + } + } /** * Though the normal client interface is to grab a Connection, in @@ -61,7 +77,9 @@ // jdbc.optional.ConnectionPool because our ObjectFactory // returns only the top level class, not the specific // jdbc2/jdbc3 implementations. - return ((PGConnectionPoolDataSource)bds).getPooledConnection(); + PooledConnection c = ((PGConnectionPoolDataSource)bds).getPooledConnection(); + connections.add(c); + return c; } /**