Re: BUG org.postgresql.Driver.connect() distorts InterruptedException
От | Andreas Rudolph |
---|---|
Тема | Re: BUG org.postgresql.Driver.connect() distorts InterruptedException |
Дата | |
Msg-id | 1543F7DE-67DE-4210-A594-E87726E4DA6C@spontech-spine.com обсуждение исходный текст |
Ответ на | Re: BUG org.postgresql.Driver.connect() distorts InterruptedException (Dave Cramer <pg@fastcrypt.com>) |
Список | pgsql-jdbc |
Am 12.08.2013 um 18:22 schrieb Dave Cramer <pg@fastcrypt.com>: > Ok, so you would like the code to not reset the interrupted exception so that when it returns the interrupted bit willstill be set and you can check for isInterrupted ? It would be acceptable to set the interrupted flag again and throw a PSQLException without the cause set (to the InterruptedException)to signal that no connection has been established to the caller. Then client code could catch the exceptionand notice that the connect request failed. Additionally it could examine the interrupted flag. That way it couldat least detected that it (the calling thread) has been interrupted. However, theoretically a PSQLException could havebeen thrown for some other reason and at the same time interruption may occur. Because of that client code cannot reliablytell whether the connection failed because of interruption. Client might want to know this is because it would behavedifferently, for example it could decide to log connect failures except for interruption. > > The SQL error is rather vague here since it is not really a SQL error, rather someone cancelled the thread. I agree. Most of the time SQL errors refer to something that happened on the server. I just mentioned it for completeness. > > > > Dave Cramer > > dave.cramer(at)credativ(dot)ca > http://www.credativ.ca > > > On Fri, Aug 9, 2013 at 4:35 AM, Andreas Rudolph <andreas.rudolph@spontech-spine.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 exceptionhandlers). After examining the source of org.postgresql.Driver I noticed that org.postgresql.Driver$ConnectThread.getResultcatches InterruptedException and throws a org.postgresql.util.PSQLExceptioninstead 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 isunspecific, 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 clientcode that needs to handle SQLExceptions differently from thread interruption -- in a concurrent environment an alreadyscheduled database query may become obsolete before it finishes because another query may be needed for example becauseof user intervention. > > Greetings > > -- > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-jdbc >
В списке pgsql-jdbc по дате отправления: