Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id E94CA4B6374 for ; Wed, 7 Dec 2011 00:30:30 -0400 (AST) Received: from mail-yx0-f174.google.com ([209.85.213.174]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RY99I-0002Kd-1n for pgsql-jdbc@postgresql.org; Wed, 07 Dec 2011 04:30:30 +0000 Received: by yenm1 with SMTP id m1so146565yen.19 for ; Tue, 06 Dec 2011 20:30:13 -0800 (PST) Received: by 10.236.176.3 with SMTP id a3mr12697162yhm.111.1323232213309; Tue, 06 Dec 2011 20:30:13 -0800 (PST) Received: from [10.0.0.53] (office1.postnewspapers.com.au. [150.101.171.128]) by mx.google.com with ESMTPS id a7sm1553077ana.5.2011.12.06.20.30.09 (version=SSLv3 cipher=OTHER); Tue, 06 Dec 2011 20:30:12 -0800 (PST) Message-ID: <4EDEEBCE.40204@ringerc.id.au> Date: Wed, 07 Dec 2011 12:30:06 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: Samuel Gendler CC: Oliver Jowett , =?ISO-8859-1?Q?Magos=E1nyi_=C1?= =?ISO-8859-1?Q?rp=E1d?= , pgsql-jdbc@postgresql.org Subject: Re: This connection has been closed References: <4EDDB1B8.70203@magwas.rulez.org> In-Reply-To: Content-Type: multipart/alternative; boundary="------------060001000504090507040002" X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201112/32 X-Sequence-Number: 22486 This is a multi-part message in MIME format. --------------060001000504090507040002 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 06/12/11 15:55, Samuel Gendler wrote: > > If you're using a 3rd party connection pool, I don't believe there is > a contract that they will necessarily validate that a connection is > still open before returning it. Most pools can be configured to issue > a 'select 1' type of query on a periodic basis to keep connections > from timing out, or just to validate that a connection is still alive > before returning it from the pool. > Relying on that alone is madness, because there's an inevitable gap between the `SELECT 1;' succeeding and the connection being passed to the app, and that's time the connection can become invalid during. It's a race, bascially. Because that race can't be eliminated the app still has to be coded to be fault-tolerant and cope with failed transactions. Validating connections is still useful if your app's idea of fault-tolerance is telling the user "something broke, please try again". You want to minimise how often that happens, so you try to make sure your pool notices a database restart promptly and flushes its connections. If your app has better fault tolerance than that, where it remembers what it tried to do and does it again if a transaction fails the first time, then there may be no point validating connections at all. -- Craig Ringer --------------060001000504090507040002 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 06/12/11 15:55, Samuel Gendler wrote:

If you're using a 3rd party connection pool, I don't believe there is a contract that they will necessarily validate that a connection is still open before returning it.  Most pools can be configured to issue a 'select 1' type of query on a periodic basis to keep connections from timing out, or just to validate that a connection is still alive before returning it from the pool.  


Relying on that alone is madness, because there's an inevitable gap between the `SELECT 1;' succeeding and the connection being passed to the app, and that's time the connection can become invalid during. It's a race, bascially. Because that race can't be eliminated the app still has to be coded to be fault-tolerant and cope with failed transactions.

Validating connections is still useful if your app's idea of fault-tolerance is telling the user "something broke, please try again". You want to minimise how often that happens, so you try to make sure your pool notices a database restart promptly and flushes its connections.

If your app has better fault tolerance than that, where it remembers what it tried to do and does it again if a transaction fails the first time, then there may be no point validating connections at all.

--
Craig Ringer
--------------060001000504090507040002--