hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oz Levanon (JIRA)" <j...@apache.org>
Subject [jira] Created: (HTTPCLIENT-938) Connection Timeout doesn't work where there's an UnknownHostException
Date Tue, 11 May 2010 13:53:43 GMT
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();
			HttpClient client = new HttpClient();
			GetMethod method = new GetMethod("http://www.987aksj239874nkjhse.gov");

			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);

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)


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

View raw message