Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 51B7B632703; Wed, 18 Nov 2009 10:32:51 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 59044-05; Wed, 18 Nov 2009 14:32:41 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from leary.csoft.net (leary.csoft.net [205.205.214.5]) by mail.postgresql.org (Postfix) with ESMTP id 5F4B86329B9; Wed, 18 Nov 2009 10:29:53 -0400 (AST) Received: by leary.csoft.net (Postfix, from userid 1112) id 5A840A365; Wed, 18 Nov 2009 09:29:50 -0500 (EST) Date: Wed, 18 Nov 2009 09:29:50 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: Mauro Molinari cc: pgsql-bugs@postgresql.org, pgsql-jdbc@postgresql.org Subject: Re: BUG #5177: Concurrency problem in AbstractJdbc23PooledConnection In-Reply-To: <200911101741.nAAHfkHV010416@wwwmaster.postgresql.org> Message-ID: References: <200911101741.nAAHfkHV010416@wwwmaster.postgresql.org> User-Agent: Alpine 2.00 (BSO 1167 2008-08-23) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-79477066-1258554590=:19001" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200911/155 X-Sequence-Number: 25119 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --0-79477066-1258554590=:19001 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed On Tue, 10 Nov 2009, Mauro Molinari wrote: > Bug reference: 5177 > PostgreSQL version: 8.3.8 > Description: Concurrency problem in AbstractJdbc23PooledConnection > Details: > > Hello, we're using PostgreSQL JDBC3 driver 8.3-605 to connect to a 8.3.8 > Postgres instance. Our application has a JTA-XA transaction infrastructure > managed by Spring and using JBoss Transactions as a JTA implementation. > We're using a connection pool of our own to pool XA connections on top of > which there's JBoss Transactions transactional driver that is managing > connections. Our connection pool infrastructure creates a PGXADataSource > from which it gets new XA connections. > > In this scenario, sometimes happens that the PostgreSQL driver fails with > the following exception: > > java.lang.NullPointerException > at > org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection$ConnectionHandler.in > voke(AbstractJdbc23PooledConnection.java:319) > at $Proxy5.close(Unknown Source) > at > com.arjuna.ats.internal.jdbc.ConnectionImple.close(ConnectionImple.java:369) > > Looking at the JDBC driver source code, it seems a concurrency problem, > because at row 304-305 the variable con is checked against null. > > What is actually happening here is that our code is closing a connection > used to read some data from the DB. This read operation is executed outside > any transaction, so JBoss Transactions is honouring the connection close > request by first calling calling close on the XA connection (and this is > causing the XA connection to be given back to our pool); after that, because > of the actual JDBC connection reports false on isClosed(), JBoss > Transactions is also calling close() on it too... and this generates the > NullPointerException given above. > > Looking at the AbstractJdbc23PooledConnection it seems there's no > synchronization at all between isClosed() and close(). My suspect is that in > the previous scenario something like this happens: > 1. thread 1: close() is invoked > 2. thread 2: isClosed() returns false > 3. thread 2: close() is invoked > > At operation 2., isClose returns false, while it should return true because > a close request has already been made on thread 1. Anyway, there should be > no problem at all to call close repeatedly on the same connection (as the > JDBC contract states), so the NullPointerException should not happen in any > case. > Attached is a test case which reproduces this problem easily. > Thanks in advance and please let me know how I can monitor this bug report > (is there any bug tracking system for PostgreSQL?). > There is no bug tracker for postgresql in general. The JDBC driver does have a bug tracker, but the mailing list is where most of the action happens. http://pgfoundry.org/tracker/?group_id=1000224 Kris Jurka --0-79477066-1258554590=:19001 Content-Type: TEXT/PLAIN; charset=US-ASCII; name=XaCloseTest.java Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename=XaCloseTest.java aW1wb3J0IGphdmEuc3FsLio7DQppbXBvcnQgamF2YXguc3FsLlhB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