Re: BUG org.postgresql.Driver.connect() distorts InterruptedException

From: Mikko Tiihonen <Mikko(dot)Tiihonen(at)nitorcreations(dot)com>
To: Dave Cramer <pg(at)fastcrypt(dot)com>, Andreas Rudolph <andreas(dot)rudolph(at)spontech-spine(dot)com>
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: BUG org.postgresql.Driver.connect() distorts InterruptedException
Date: 2013-08-13 11:07:18
Message-ID: b8916265a20c40f680b25b261f133648@AMSPR07MB018.eurprd07.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I believe that setting the interrupted bit back on for the thread and throwing SQLException is the correct option.

Any threads that catch InterruptedException should either (in preference order)
1) rethrow it as is (if allowed by method signature)
2) set the interrupted bit and throw some other exception
3) continue and set the interrupted bit in finally block (only for critical methods that are doing some important cleanup)

-Mikko
________________________________
From: pgsql-jdbc-owner(at)postgresql(dot)org <pgsql-jdbc-owner(at)postgresql(dot)org> on behalf of Dave Cramer <pg(at)fastcrypt(dot)com>
Sent: 12 August 2013 19:22
To: Andreas Rudolph
Cc: List
Subject: Re: [JDBC] BUG org.postgresql.Driver.connect() distorts InterruptedException

Ok, so you would like the code to not reset the interrupted exception so that when it returns the interrupted bit will still be set and you can check for isInterrupted ?

The SQL error is rather vague here since it is not really a SQL error, rather someone cancelled the thread.

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On Fri, Aug 9, 2013 at 4:35 AM, Andreas Rudolph <andreas(dot)rudolph(at)spontech-spine(dot)com<mailto:andreas(dot)rudolph(at)spontech-spine(dot)com>> wrote:
Hi there!

+ JDBC driver build number
9.1-903

+ Server
PostgreSQL 9.1.9 on i686-pc-linux-gnu, compiled by gcc-4.4.real (Debian 4.4.5-8) 4.4.5, 32-bit

+ Error message / stack trace

org.postgresql.util.PSQLException: Beim Verbindungsversuch trat eine Unterbrechung auf.
at org.postgresql.Driver$ConnectThread.getResult(Driver.java:365)
at org.postgresql.Driver.connect(Driver.java:269)
...

+ Description

Recently I discovered this problem because it prevents to tell other SQLExceptions and interruption apart (in the exception handlers). After examining the source of org.postgresql.Driver I noticed that org.postgresql.Driver$ConnectThread.getResult catches InterruptedException and throws a org.postgresql.util.PSQLException instead BUT without supplying the InterruptedException as the cause (exception chaining) and without resetting the interrupted flag via Thread.currentThread().interrupt() (SQL error code / SQL state is unspecific, too). Please note that this behavior is present in 9.2-1003, too.

Therefore I suggest that the handling of InterruptedException should be changed so it becomes more interoperable with client code that needs to handle SQLExceptions differently from thread interruption -- in a concurrent environment an already scheduled database query may become obsolete before it finishes because another query may be needed for example because of user intervention.

Greetings

--
Sent via pgsql-jdbc mailing list (pgsql-jdbc(at)postgresql(dot)org<mailto:pgsql-jdbc(at)postgresql(dot)org>)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Andreas Rudolph 2013-08-13 15:19:53 Re: BUG org.postgresql.Driver.connect() distorts InterruptedException
Previous Message Florent Guillaume 2013-08-13 10:46:15 Re: BUG org.postgresql.Driver.connect() distorts InterruptedException