Thread: Strange exception opening JDBC connection

Strange exception opening JDBC connection

From
Kevin Schmidt
Date:
Hi,

I am getting a strange exception when opening a JDBC connection.
Specifically it is:

java.net.BindException: Address already in use: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:295)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:161)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148)
    at java.net.Socket.connect(Socket.java:425)
    at java.net.Socket.connect(Socket.java:375)
    at java.net.Socket.<init>(Socket.java:290)
    at java.net.Socket.<init>(Socket.java:118)
    at org.postgresql.PG_Stream.<init>(PG_Stream.java:38)
    at
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Connection.java:154)
    at org.postgresql.Driver.connect(Driver.java:120)
    at java.sql.DriverManager.getConnection(DriverManager.java:512)
    at java.sql.DriverManager.getConnection(DriverManager.java:171)

Connections prior to this one have worked fine so the server is up and
running, and it seems strange that an address already in use would
happen when a client connection is made.  Any ideas what is going on?
Does the JDBC driver try to listen on a port?

Thanks,

Kevin


Re: Strange exception opening JDBC connection

From
Barry Lind
Date:
Kevin,

I can't explain what you are seeing.  The driver does not listen on any
port.

--Barry


Kevin Schmidt wrote:
> Hi,
>
> I am getting a strange exception when opening a JDBC connection.
> Specifically it is:
>
> java.net.BindException: Address already in use: connect
>    at java.net.PlainSocketImpl.socketConnect(Native Method)
>    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:295)
>    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:161)
>    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148)
>    at java.net.Socket.connect(Socket.java:425)
>    at java.net.Socket.connect(Socket.java:375)
>    at java.net.Socket.<init>(Socket.java:290)
>    at java.net.Socket.<init>(Socket.java:118)
>    at org.postgresql.PG_Stream.<init>(PG_Stream.java:38)
>    at
> org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Connection.java:154)
>
>    at org.postgresql.Driver.connect(Driver.java:120)
>    at java.sql.DriverManager.getConnection(DriverManager.java:512)
>    at java.sql.DriverManager.getConnection(DriverManager.java:171)
>
> Connections prior to this one have worked fine so the server is up and
> running, and it seems strange that an address already in use would
> happen when a client connection is made.  Any ideas what is going on?
> Does the JDBC driver try to listen on a port?
>
> Thanks,
>
> Kevin
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
>      joining column's datatypes do not match
>



Re: Strange exception opening JDBC connection

From
Paul Thomas
Date:
On 08/07/2003 17:27 Kevin Schmidt wrote:
> [snip]
> Connections prior to this one have worked fine so the server is up and
> running, and it seems strange that an address already in use would
> happen when a client connection is made.  Any ideas what is going on?
> Does the JDBC driver try to listen on a port?

Looks like some kind of OS TCP/IP stack problem. What OS are you running?
I've seen wierd things like this occasionally with M$ OS's - especially 95
& 98.

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants         |
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+

Re: Strange exception opening JDBC connection

From
Kevin Schmidt
Date:
Paul Thomas wrote:

>
> On 08/07/2003 17:27 Kevin Schmidt wrote:
>
>> [snip]
>> Connections prior to this one have worked fine so the server is up
>> and running, and it seems strange that an address already in use
>> would happen when a client connection is made.  Any ideas what is
>> going on?  Does the JDBC driver try to listen on a port?
>
>
> Looks like some kind of OS TCP/IP stack problem. What OS are you
> running? I've seen wierd things like this occasionally with M$ OS's -
> especially 95 & 98.

Using Win2K SP2, so it being on Windows is common with your experience.
Any ideas on what causes it or a way to work around it?

Kevin


Re: Strange exception opening JDBC connection

From
Paul Thomas
Date:
On 08/07/2003 19:45 Kevin Schmidt wrote:

> Using Win2K SP2, so it being on Windows is common with your experience.

I can't swear that other OS's don't occasionally exhibit this 'feature'
but I've only ever seen it on Windows machines and even then only once or
twice ever. BTW, Java/JDBC was not involved in these occurances - they
happened with a C application which I used to maintain.

> Any ideas on what causes it or a way to work around it?

We spent ages trawling through our code trying to see what (if anything)
we were doing wrong. We never resolved it. Nor could we reproduce the
problem. It was just something that seemed to barf occasionally. Are you
getting this repeatedly or has the problem misteriously gone away?

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants         |
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+

Re: Strange exception opening JDBC connection

From
Jochem van Dieten
Date:
Kevin Schmidt wrote:
>
> java.net.BindException: Address already in use: connect
>    at java.net.PlainSocketImpl.socketConnect(Native Method)
>    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:295)
>    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:161)
>    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148)
>    at java.net.Socket.connect(Socket.java:425)
>
>    at java.net.Socket.connect(Socket.java:375)
>    at java.net.Socket.<init>(Socket.java:290)
>    at java.net.Socket.<init>(Socket.java:118)
>    at org.postgresql.PG_Stream.<init>(PG_Stream.java:38)
>
>    at
> org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Connection.java:154)
>    at org.postgresql.Driver.connect(Driver.java:120)
>    at java.sql.DriverManager.getConnection(DriverManager.java:512)
>    at java.sql.DriverManager.getConnection(DriverManager.java:171)
>
> Connections prior to this one have worked fine so the server is up and
> running, and it seems strange that an address already in use would
> happen when a client connection is made.  Any ideas what is going on?
> Does the JDBC driver try to listen on a port?

Possible explanation:
http://forum.java.sun.com/thread.jsp?thread=346820&forum=11&message=1434780

Microsoft documentation on the settings to change:
http://www.microsoft.com/windows2000/techinfo/howitworks/communications/networkbasics/tcpip_implement.asp
See "TCP TIME-WAIT Delay" on page 45 (but I would recommend reading it
all, it has a lot on hardening a Windows TCP/IP stack).

If this is caused by frequent connections to a PostgreSQL server (from
for instance a web application server) you might want to look into using
a connection pool :-)

Jochem