pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Laurent Sylvain <sylvain.laurent@elca.ch>
Cc: 'pgsql-jdbc@postgresql.org' <pgsql-jdbc@postgresql.org>
Subject: Re: Bug (and fix): leaks of TCP connections when connected
Date: Tue, 22 Jun 2004 04:37:15 -0500 (EST)
Message-ID: <Pine.BSO.4.56.0406220433020.20144@leary.csoft.net> (raw)
In-Reply-To: <A13B47F8EC3FD111A91500C04FD2A2820567E6FA@exchange.elca.ch>
References: <A13B47F8EC3FD111A91500C04FD2A2820567E6FA@exchange.elca.ch>



On Mon, 21 Jun 2004, Laurent Sylvain wrote:

> 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:
> 

I've applied the attached patch to the 7.4 and 7.5 cvs trees.  It adds the 
pgStream.close() you suggested as well as closing the stream for other 
connection failures such as authentication failures or lack of ssl 
support.

Kris Jurka

Attachments:

tcpclose.patch (text/plain, 1.9K) download ? built ? jdbcbuild.sh Index: org/postgresql/jdbc1/AbstractJdbc1Connection.java =================================================================== RCS file: /cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v retrieving revision 1.27.2.2 diff -c -r1.27.2.2 AbstractJdbc1Connection.java *** org/postgresql/jdbc1/AbstractJdbc1Connection.java 10 Feb 2004 01:58:48 -0000 1.27.2.2 --- org/postgresql/jdbc1/AbstractJdbc1Connection.java 22 Jun 2004 09:23:37 -0000 *************** *** 208,218 **** throw new PSQLException ("postgresql.con.failed", PSQLState.CONNECTION_UNABLE_TO_CONNECT, e); } ! //Now do the protocol work ! if (haveMinimumCompatibleVersion("7.4")) { ! openConnectionV3(host,port,info,database,url,d,password); ! } else { ! openConnectionV2(host,port,info,database,url,d,password); } } --- 208,228 ---- throw new PSQLException ("postgresql.con.failed", PSQLState.CONNECTION_UNABLE_TO_CONNECT, e); } ! try { ! //Now do the protocol work ! if (haveMinimumCompatibleVersion("7.4")) { ! openConnectionV3(host,port,info,database,url,d,password); ! } else { ! openConnectionV2(host,port,info,database,url,d,password); ! } ! } catch (SQLException sqle) { ! // if we fail to completely establish a connection, ! // close down the socket to not leak resources. ! try { ! pgStream.close(); ! } catch (IOException ioe) { } ! ! throw sqle; } } *************** *** 305,310 **** --- 315,321 ---- //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 + pgStream.close(); try { pgStream = new PGStream(p_host, p_port);

view thread (10+ messages)  latest in thread

Message-ID: <Pine.BSO.4.56.0406220433020.20144@leary.csoft.net>
Permalink:  ../Pine.BSO.4.56.0406220433020.20144@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.56.0406220433020.20144@leary.csoft.net

 ·  · 

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: books@ejurka.com, sylvain.laurent@elca.ch
  Subject: Re: Bug (and fix): leaks of TCP connections when connected
  In-Reply-To: <Pine.BSO.4.56.0406220433020.20144@leary.csoft.net>
  References: <A13B47F8EC3FD111A91500C04FD2A2820567E6FA@exchange.elca.ch> <Pine.BSO.4.56.0406220433020.20144@leary.csoft.net>

* 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