Re: Problem

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: Problem
Дата
Msg-id D960CB61B694CF459DCFB4B0128514C202FF651E@exadv11.host.magwien.gv.at
обсуждение исходный текст
Ответ на Problem  (Mauricio Solis <mauricio.solis.h@gmail.com>)
Ответы Re: Problem  (Oliver Jowett <oliver@opencloud.com>)
Список 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

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Mauricio Solis
Дата:
Сообщение: Problem
Следующее
От: Oliver Jowett
Дата:
Сообщение: Re: Problem