pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@2ndquadrant.com>
To: Kevin Wooten <kdubb@me.com>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: A new JDBC driver...
Date: Fri, 15 Mar 2013 15:16:35 +0800
Message-ID: <5142CAD3.4070308@2ndquadrant.com> (raw)
In-Reply-To: <D61562E4-6497-4262-8717-703015512E05@me.com>
References: <C456E460-078E-4562-8921-39000ED4D71A@me.com>
	<5141588D.9030405@2ndquadrant.com>
	<D61562E4-6497-4262-8717-703015512E05@me.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

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. 
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.runFinalizersOnExit()|,
    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/, ยง12.6.2, "Finalizer
    Invocations are Not Ordered"
    <http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.6.2; [JLS
    2005
    <https://www.securecoding.cert.org/confluence/display/java/AA.+References#AA.References-JLS05;]:


        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
    <https://www.securecoding.cert.org/confluence/display/java/BB.+Glossary#BB.Glossary-invariant;.
  * 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
    <https://www.securecoding.cert.org/confluence/display/java/AA.+References#AA.References-Boehm05;]
    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.

-- 
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

view thread (31+ messages)  latest in thread

Message-ID: <5142CAD3.4070308@2ndquadrant.com>
Permalink:  ../5142CAD3.4070308@2ndquadrant.com/
Also on:    postgresql.org/message-id/5142CAD3.4070308@2ndquadrant.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: craig@2ndquadrant.com, kdubb@me.com
  Subject: Re: A new JDBC driver...
  In-Reply-To: <5142CAD3.4070308@2ndquadrant.com>
  References: <C456E460-078E-4562-8921-39000ED4D71A@me.com> <5141588D.9030405@2ndquadrant.com> <D61562E4-6497-4262-8717-703015512E05@me.com> <5142CAD3.4070308@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox