Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UGOsm-0002Ea-Gv for pgsql-jdbc@arkaria.postgresql.org; Fri, 15 Mar 2013 07:16:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UGOsl-0001wg-Uu for pgsql-jdbc@arkaria.postgresql.org; Fri, 15 Mar 2013 07:16:51 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UGOsk-0001wb-SU for pgsql-jdbc@postgresql.org; Fri, 15 Mar 2013 07:16:51 +0000 Received: from outmail148095.authsmtp.com ([62.13.148.95]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UGOsi-0001c3-Hp for pgsql-jdbc@postgresql.org; Fri, 15 Mar 2013 07:16:50 +0000 Received: from mail-c233.authsmtp.com (mail-c233.authsmtp.com [62.13.128.233]) by punt8.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id r2F7Gi9T083164; Fri, 15 Mar 2013 07:16:44 GMT Received: from ayaki.localdomain (124-169-247-22.dyn.iinet.net.au [124.169.247.22]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/) with ESMTP id r2F7Gatt021924 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Fri, 15 Mar 2013 07:16:39 GMT Message-ID: <5142CAD3.4070308@2ndquadrant.com> Date: Fri, 15 Mar 2013 15:16:35 +0800 From: Craig Ringer Organization: 2nd Quadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130219 Thunderbird/17.0.3 MIME-Version: 1.0 To: Kevin Wooten CC: "pgsql-jdbc@postgresql.org" Subject: Re: A new JDBC driver... References: <5141588D.9030405@2ndquadrant.com> In-Reply-To: X-Enigmail-Version: 1.5.1 Content-Type: multipart/alternative; boundary="------------010504000805090703030200" X-Server-Quench: 48b20cbc-8d40-11e2-a49c-0025907707a1 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdxZQATClZeVg0b BQteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaQBbYFhD HGQLWldEUFp7WGV/ bwsfbAdZfEtIVhto VE9XQFBNFgBqBAMA SFwcJB4FJkECeHxx bERmEHReX0dzO0J1 EExURj9VeG80bGAC UUENdR4FdAoZYx9F aFV2VHQKYWJWZzQC El17DBIdFx5qYA0d RAwSZXA+a21DEiQ9 WR0YW3NpdQAA X-Authentic-SMTP: 61633235383639.1021:706 X-AuthFastPath: 0 (Was 255) X-AuthSMTP-Origin: 124.169.247.22/2525 X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Pg-Spam-Score: -1.3 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org This is a multi-part message in MIME format. --------------010504000805090703030200 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by punt8.authsmtp.com id r2F7Gi9T083164 On 03/15/2013 01:15 PM, Kevin Wooten wrote: > After a bit of messing around I finally settled on the much maligned > "finalizer" to kill the connection if it's abandoned.=20 Oh, and re finalizers: https://www.securecoding.cert.org/confluence/display/java/MET12-J.+Do+not= +use+finalizers In particular, these points: * There is no fixed time at which finalizers must be executed because this depends on the JVM. The only guarantee is that any finalizer method that executes will do so sometime after the associated object has become unreachable (detected during the first cycle of garbage collection) and sometime before the garbage collector reclaims the associated object's storage (during the garbage collector's second cycle). Execution of an object's finalizer may be delayed for an /arbitrarily/ long time after the object becomes unreachable. Consequently, invoking time-critical functionality such as closing file handles in an object's |finalize()| method is problematic. * The JVM may terminate without invoking the finalizer on some or all unreachable objects. Consequently, attempts to update critical persistent state from finalizer methods can fail without warning. Similarly, Java lacks any guarantee that finalizers will execute on process termination. Methods such as |System.gc()|, |System.runFinalization()|, |System.runFinalizersOn= Exit()|, and |Runtime.runFinalizersOnExit()| either lack such guarantees or have been deprecated because of lack of safety and potential for deadlock. * According to the /Java Language Specification/, =A712.6.2, "Finalizer Invocations are Not Ordered" [JLS 2005 ]: The Java programming language imposes no ordering on |finalize()| method calls. Finalizers [of different objects] may be called in any order, or even concurrently. One consequence is that slow-running finalizers can delay execution of other finalizers in the queue. Further, the lack of guaranteed ordering can lead to substantial difficulty in maintaining desired program invariants . * Use of finalizers can introduce synchronization issues even when the remainder of the program is single-threaded. The |finalize()| methods are invoked by the garbage collector from one or more threads of its choice; these threads are typically distinct from the |main()| thread, although this property is not guaranteed. When a finalizer is necessary, any required cleanup data structures must be protected from concurrent access. See the JavaOne presentation by Hans J. Boehm [Boehm 2005 ] for additional information. In particular I would be concerned that a thread refcounting system would be subject to ordering problems or deadlocks introduced by attempts to introduce fixes for ordering problems. I really need to look into how other JDBC drivers handle these issues; it's not like this is a new problem. --=20 Craig Ringer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --------------010504000805090703030200 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by punt8.authsmtp.com id r2F7Gi9T083164
On 03/15/2013 01:15 PM, Kevin Wooten wrote:
After a bit of messing around I finally settled on the much maligned "finalizer" to kill the connection if it's abandoned.=A0 <= br>
Oh, and re finalizers:

https://www.securecoding.cert.org/confluence/dis= play/java/MET12-J.+Do+not+use+finalizers

In particular, these points:

  • There is no fixed time at which finalizers must be executed because this depends on the JVM. The only guarantee is that any finalizer method that executes will do so sometime after the associated object has become unreachable (detected during the first cycle of garbage collection) and sometime before the garbage collector reclaims the associated object's storage (during the garbage collector's second cycle). Execution of an object's finalizer may be delayed for an=A0arbitrarily=A0= long time after the object becomes unreachable. Consequently, invoking time-critical functionality such as closing file handles in an object's=A0finalize()=A0method is problematic= .
  • The JVM may terminate without invoking the finalizer on some or all unreachable objects. Consequently, attempts to update critical persistent state from finalizer methods can fail without warning. Similarly, Java lacks any guarantee that finalizers will execute on process termination. Methods such as=A0System.gc(),=A0System.runFinal= ization(),=A0System.runFinal= izersOnExit(), and=A0Runtime.runFinalizersOnExit()=A0either lack such guarantees or have been deprecated because of lack of safety and potential for deadlock.

  • According to the=A0Java Language Specification,=A0=A712.6.2, "Finalizer Invocations are Not Ordered"=A0[JLS 2005]:

    = The Java programming language imposes no ordering on=A0finalize()<= /code>=A0method calls. Finalizers [of different objects] may be called in any order, or even concurrently.

    One consequence is that slow-running finalizers can delay execution of other finalizers in the queue. Further, the lack of guaranteed ordering can lead to substantial difficulty in maintaining desired program= =A0invariants.
  • Use of finalizers can introduce synchronization issues even when the remainder of the program is single-threaded. The=A0finalize()=A0methods are invoked b= y the garbage collector from one or more threads of its choice; these threads are typically distinct from the=A0main()=A0thread, although this property is not guaranteed. When a finalizer is necessary, any required cleanup data structures must be protected from concurrent access. See the JavaOne presentation by Hans J. Boehm [Boehm 2005] for additional information.
In particular I would be concerned that a thread refcounting system would be subject to ordering problems or deadlocks introduced by attempts to introduce fixes for ordering problems.

I really need to look into how other JDBC drivers handle these issues; it's not like this is a new problem.
--=20
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services
--------------010504000805090703030200--