Bug (and fix): leaks of TCP connections when connected to a <7.4 server - Mailing list pgsql-jdbc

From Laurent Sylvain
Subject Bug (and fix): leaks of TCP connections when connected to a <7.4 server
Date
Msg-id A13B47F8EC3FD111A91500C04FD2A2820567E6FA@exchange.elca.ch
Whole thread Raw
Responses Re: Bug (and fix): leaks of TCP connections when connected  (Kris Jurka <books@ejurka.com>)
Re: Bug (and fix): leaks of TCP connections when connected  (Oliver Jowett <oliver@opencloud.com>)
Re: Bug (and fix): leaks of TCP connections when connected  (Kris Jurka <books@ejurka.com>)
List pgsql-jdbc
Hello,

I experienced some TCP connection leaks when using PGSQL JDBC driver 7.4
(build 214) to connect to a 7.3.4 server.
The symptoms are that when performing a netstat on the client machine, many
connections were in the CLOSE_WAIT state.

The problem is that the driver tries to connect using v3 protocol and when
it sees that the server doesn't understand it, it opens a new connection
(PGStream) to the server without closing the previous one:

AbstractJdbc1Connection.java line 304 and on:
    if (l_elen > 30000) {
        //if the error length is > than 30000 we assume this is
really a v2 protocol
        //server so try again with a v2 connection
        //need to create a new connection and try again
        try
        {
            pgStream = new PGStream(p_host, p_port);
        }
        catch (ConnectException cex)

A quick fix is to do a pgStream.close(); before instantiating a new
PGStream, but I don't know very well the sources and it might have other
side effects.

To circumvent the problem while waiting for an eventual new version of the
driver, I added "?compatible=7.3" to the connection URL...

I hope it'll improve the driver ;-)

Sylvain Laurent

pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: Re: proposal for CallableStatements to handle multiple out
Next
From: Markus Schaber
Date:
Subject: Re: blob without largeobject api