Re: Detecting 'socket errors' - closing the Connection object - Mailing list pgsql-jdbc

From Dmitry Tkach
Subject Re: Detecting 'socket errors' - closing the Connection object
Date
Msg-id 3F1C3692.9030903@openratings.com
Whole thread Raw
In response to Re: Detecting 'socket errors' - closing the Connection object  ("David Wall" <d.wall@computer.org>)
List pgsql-jdbc
David Wall wrote:

>> It is not that trivial for JDBC to be able to detect and handle all the
>>cases when the connection can be considered "closed" as opposed
>>legitimate error conditions...
>>
>>
>
>Why is that the case?  I mean, if the library gets a socket error, rather
>than error from the database, it's an I/O error that probably means a TCP
>socket won't really be okay anymore, and it could then close it.
>
>
But why do you only care about socket errors? What is so special about them?
What if you execute a query, and it crashes the backend? You'll get a
SQLException from the backend (not a socket error), but the connection
will still be invalid.

>>Besides, if isClosed () returned true in such situations, it would be
>>lying :-)
>>
>>
>
>Well, not if it closed it after it got an error.  I mean, I don't open the
>socket either, but the JDBC library should be able to figure it out, no?
>
>
I am sure some application code would get *very* surprised if
connections started to get closed "automagically" under it :-)
You don't want to preceed every statement executing a query with (if
(!connection.isClosed ()) check, do you?

>That will work, but doesn't adding an entire call to the backend database on
>each use a connection from the pool seem excessive?  I mean, if I'm going to
>all that trouble, I might as well not pool the connection at all -- the
>overhead can't be that much different.
>
>
>
It *is* very different... With this piece of code, the only overhead is,
pretty much, just the cost of sending about 15 bytes over the wire...
that's pretty negligeable...
You are still saving on the expensive stuff like establishing a new TCP
connection, creating file descriptors, multiple network round trips for
authentication, constructing, and starting a new backend process,
setting up memory structures etc, etc, etc...


Dima



pgsql-jdbc by date:

Previous
From: Darin Ohashi
Date:
Subject: Re: IN clauses via setObject(Collection) [Was: Re: Prepare
Next
From: Barry Lind
Date:
Subject: Re: Timestamp problem