Re: Problem

From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: <mauricio(dot)solis(dot)h(at)gmail(dot)com>, <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Problem
Date: 2009-03-31 07:53:39
Message-ID: D960CB61B694CF459DCFB4B0128514C202FF651E@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Mauricio Solis wrote:
> I have a problem wiht de driver.
>
> If the IP address of the postgresql server is wrong, then the aplication
> take a lot of time in finish, iven I try to set
> DriverManager.setLoginTimeout(3), but the problem still.
>
> I used a sniffer (tcpdump) and I realiced that my java aplication insist
> in try to connect to the wrong IP. How I can finish the aplication when
> the IP server is wrong ???

I don't think that you run into the login timeout here, you rather encounter
a TCP timeout. Before JDBC can connect, a TCP connection must be established.
Since the destination IP address does not exist, your computer is sending
SYN requests that do not receive an answer until the TCP layer "gives up".

You can find this described in chapter 4.2.3.5 of RFC 1122, which also states
that the timeout "for a SYN segment MUST be set large enough to provide
retransmission of the segment for at least 3 minutes".

If you wait long enough, you eventually get an exception, right?
It's just that the length of time it takes is unacceptable for you.

JDBC cannot influence this as it is on a lower layer.

I can think of two options:
- You can configure the TCP stack in your operating system kernel to
make this timeout shorter. The drawback is that this usually affects
all connections from this machine and can be a dangerous thing to do.
- You can try to work around it in Java by using threads that watch
each other and report an error to the user if the connection attempt
exceeds a certain time.

Maybe you can avoid this problem by not using IP addresses at all.
If you use DNS names, you will get a name resolution error quickly if
you try to connect to a host that does not exist.

Yours,
Laurenz Albe

In response to

  • Problem at 2009-03-27 17:09:31 from Mauricio Solis

Responses

  • Re: Problem at 2009-03-31 08:31:34 from Oliver Jowett

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2009-03-31 08:31:34 Re: Problem
Previous Message Mauricio Solis 2009-03-27 17:09:31 Problem