You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Oz Levanon (JIRA)" <ji...@apache.org> on 2010/05/12 09:30:41 UTC

[jira] Closed: (HTTPCLIENT-938) Connection Timeout doesn't work where there's an UnknownHostException

     [ https://issues.apache.org/jira/browse/HTTPCLIENT-938?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oz Levanon closed HTTPCLIENT-938.
---------------------------------


Thanks for the fast responses. 
I'll try andsee what I can do on the machine side to speed up DNS resolution. If it won't succeed I'll use the workaround suggested above and access the DNS before so that its failed resolution will be cached.

Thanks,
Oz

> 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