Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 6AD33B5DC5E for ; Tue, 20 Sep 2011 11:03:41 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 41316-01-2 for ; Tue, 20 Sep 2011 14:03:33 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from auth-smtp.nebula.fi (auth-smtp.nebula.fi [217.30.180.105]) by mail.postgresql.org (Postfix) with ESMTP id 85ADCB5DE45 for ; Tue, 20 Sep 2011 11:00:55 -0300 (ADT) Received: from quadvadis.localdomain (gw.nitor.fi [83.145.228.24]) (authenticated bits=0) by auth-smtp.nebula.fi (8.13.4/8.13.4) with ESMTP id p8KE0eH9000834 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 20 Sep 2011 17:00:41 +0300 Message-ID: <4E789C89.7060606@nitorcreations.com> Date: Tue, 20 Sep 2011 17:00:41 +0300 From: Mikko Tiihonen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2 MIME-Version: 1.0 To: Dave Cramer CC: Oliver Jowett , pgsql-jdbc@postgresql.org Subject: Re: binary patch problems References: <4E734D08.10205@nitorcreations.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201109/74 X-Sequence-Number: 22192 On 09/19/2011 01:03 PM, Dave Cramer wrote: > Hi Mikko, > > My suggestion would be to fix it. Finally had some time to look into this. Closing the result set of the describe query fixes the test failure for me. -Mikko --- org/postgresql/jdbc2/AbstractJdbc2Statement.java.orig 2011-09-20 16:55:18.130947602 +0300 +++ org/postgresql/jdbc2/AbstractJdbc2Statement.java 2011-09-20 16:56:02.310694214 +0300 @@ -541,6 +541,8 @@ int flags2 = flags | QueryExecutor.QUERY_DESCRIBE_ONLY; StatementResultHandler handler2 = new StatementResultHandler(); connection.getQueryExecutor().execute(queryToExecute, queryParameters, handler2, 0, 0, flags2); + ResultWrapper result2 = handler2.getResults(); + result2.getResultSet().close(); } StatementResultHandler handler = new StatementResultHandler(); > On Fri, Sep 16, 2011 at 7:14 PM, Oliver Jowett wrote: >> On 17 September 2011 01:20, Mikko Tiihonen >> wrote: >> >>> If I debugged it correctly it looks like the query statement is closed by >>> finalizer during the test which in turn closes the relevant portals. >>> If I add stmt.close() to the end of the test there are no failures as it >>> keeps the GC from killing of the statement during the test. >>> >>> But why I only seem to get it when running with binary transfer patches I do >>> not know. So there must be something in the patches that I cannot spot. >> >> (I am halfway through my first coffee of the day. YMMV) >> >> The test code holds a reference to the returned ResultSet, but doesn't >> keep a reference to the Statement itself after calling executeQuery(). >> Normally this isn't a problem because there is a strong ref from a >> ResultSet to its owning Statement, so while you are using a particular >> ResultSet the creating statement remains reachable. >> >> The problem seems to be introduced in the patch to executeQuery if >> (ForceBinaryTransfers). This delegates to a new PreparedStatement >> ("inner PreparedStatement") and splices its resultset ("inner >> resultset") back into the surrounding Statement ("outer Statement") >> and returns that. >> >> However the inner ResultSet has the wrong parent Statement for that >> context (ResultSet.getStatement() will return the "inner >> PreparedStatement" not the "outer Statement") - which is a separate >> problem, but also causes the GC problems as well, as now there's no >> strong ref from the returned ResultSet to the Statement that the >> client created it via. >> >> So in the test code we end up with: >> (a) a strong ref to the inner ResultSet, directly; and >> (b) a strong ref to the inner PreparedStatement, via the statement >> reference of the inner ResultSet. >> >> .. but no strong ref to the outer Statement. So the outer Statement >> becomes garbage right after the call to executeQuery(), and if you are >> unlucky with GC timing, it can be finalized and closed under you, >> which then closes the inner ResultSet. >> >> Adding a call to stmt.close() means that the outer Statement still has >> a strong reference directly from test code up until that point, so it >> doesn't get finalized early. >> >> At a glance, executeQuery() is also broken for queries that return >> multiple resultsets if ForceBinaryTransfers is enabled - you only get >> the first resultset back. >> >> Oliver >>