hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ortwin Glück (JIRA) <j...@apache.org>
Subject [jira] Issue Comment Edited: (HTTPCLIENT-938) Connection Timeout doesn't work where there's an UnknownHostException
Date Tue, 11 May 2010 14:19:42 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-938?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12866153#action_12866153
] 

Ortwin Glück edited comment on HTTPCLIENT-938 at 5/11/10 10:19 AM:
-------------------------------------------------------------------

InetAddress.getByName(String) does a DNS lookup. That loopkup is not part of the connection
timeout.

The JDK doesn't let you specify a timeout here. It simply uses the timeouts of the underlying
name resolution mechanism. 

Anyway I suspect the effect is not limited to Java. You should be able to observe the same
timeouts using nslookup or the host command from a terminal. In a "normal" environment DNS
lookup timeouts should be of the order of 1-3 seconds, but not 20 seconds. So I strongly suspect
your network setup is broken.

Several things can lead to such insane timeouts:
- DNS server not reachable (UDP port 53), but ICMP is filtered, so client can not fail fast
- local firewall on DNS server dropping packets on closed TCP ports instead of sending RST
- intermediate firewalls blocking ICMP messages
- lookups performed over IPv6, but missing IPv6 connectivity
- AAAA record lookups before A record lookup
- your DNS server performs full recursion but no caching. Clients should always query a DNS
cache, never a recursor only.

Workaround: You may perform the lookup before sending the request, so the result is already
pre-cached.

      was (Author: oglueck):
    InetAddress.getByName(String) does a DNS lookup. That loopkup is not part of the connection
timeout.

The JDK doesn't let you specify a timeout here. It simply uses the timeouts of the underlying
name resolution mechanism. 

Anyway I suspect the effect is not limited to Java. You should be able to observe the same
timeouts using nslookup or the host command from a terminal. In a "normal" environment DNS
lookup timeouts should be of the order of 1-3 seconds, but not 20 seconds. So I strongly suspect
your network setup is broken.

Several things can lead to such insane timeouts:
- DNS server not reachable (UDP port 53), but ICMP is filtered, so client can not fail fast
- local firewall on DNS server dropping packets on closed TCP ports instead of sending RST
- intermediate firewalls blocking ICMP messages
- lookups performed over IPv6, but missing IPv6 connectivity
- AAAA record lookups before A record lookup

Workaround: You may perform the lookup before sending the request, so the result is already
pre-cached.
  
> Connection Timeout doesn't work where there's an UnknownHostException
> ---------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-938
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-938
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient, HttpConn
>    Affects Versions: 3.1 Final
>         Environment: Linux OS
>            Reporter: Oz Levanon
>
> When trying to connect to an unresolvable host (using the host name, not the IP), it
seems that none of the timeouts has any effect.
> On one of my machines the UnknownHostConnection is only thrown after 20 seconds, even
though my timeouts are set to 1 second.
> Please note that the duration of the timeout changes between computers. On my Windows
XP machine it takes only 500ms to throw the exception, but on a Linux machine (probably with
a more problematic DNS) it takes 20 seconds.
> This issue may be somehow related to issue 478 (https://issues.apache.org/jira/browse/HTTPCLIENT-478),
but I couldn't find any help in any of the solutions there.
> I suspect the problem occurs when Java's InetSocketAddress constructor calls InetAddress.getByName(String)
after DefaultProtocolSocketFactory.createSocket tries to create a new socket.
> Example code:
> --------------------
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.methods.GetMethod;
> public class HttpConnectionTimeoutProblem
> {
> 	public static void main(String[] args)
> 	{
> 		long start = System.currentTimeMillis();
> 		try
> 		{
> 			HttpClient client = new HttpClient();
> 			client.getParams().setConnectionManagerTimeout(1000);
> 			client.getParams().setSoTimeout(1000);
> 			GetMethod method = new GetMethod("http://www.987aksj239874nkjhse.gov");
> 			method.getParams().setSoTimeout(1000);
> 			int httpRc = client.executeMethod(method);
> 			System.out.println("httpRc = " + httpRc);
> 		}
> 		catch (Exception e)
> 		{
> 			long time = System.currentTimeMillis() - start;
> 			System.out.println("Exception caught after " + time + ": " + e);
> 			e.printStackTrace();
> 		}
> 	}
> }
> The output from this is (on my Linux machine)
> --------------------------------------------------------------
> log4j:WARN No appenders could be found for logger (org.apache.commons.httpclient.HttpClient).
> log4j:WARN Please initialize the log4j system properly.
> Exception caught after 20593: java.net.UnknownHostException: www.987aksj239874nkjhse.gov
> java.net.UnknownHostException: www.987aksj239874nkjhse.gov
>         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
>         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
>         at java.net.Socket.connect(Socket.java:520)
>         at java.net.Socket.connect(Socket.java:470)
>         at java.net.Socket.<init>(Socket.java:367)
>         at java.net.Socket.<init>(Socket.java:240)
>         at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:79)
>         at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:121)
>         at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
>         at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
>         at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
>         at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
>         at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
>         at HttpConnectionTimeoutProblem.main(HttpConnectionTimeoutProblem.java:17)
> Thanks

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message