Thread: Problem

Problem

From
Mauricio Solis
Date:
Hi:
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 ???


Please Help My



Re: Problem

From
"Albe Laurenz"
Date:
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

Re: Problem

From
Oliver Jowett
Date:
Albe Laurenz wrote:
> 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".

Yes, but if you set a login timeout the driver will do the connect in a
separate thread, so while that thread is indeed blocked waiting for a
TCP-level timeout, the main application thread should not remain blocked.

Mauricio, do you have a testcase that shows the problem?

-O