Return-Path: Delivered-To: apmail-hc-dev-archive@www.apache.org Received: (qmail 11224 invoked from network); 11 May 2010 18:52:05 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 11 May 2010 18:52:05 -0000 Received: (qmail 13681 invoked by uid 500); 11 May 2010 18:52:05 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 13599 invoked by uid 500); 11 May 2010 18:52:05 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 13591 invoked by uid 99); 11 May 2010 18:52:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 May 2010 18:52:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 May 2010 18:52:02 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o4BIpfXG010120 for ; Tue, 11 May 2010 18:51:41 GMT Message-ID: <22774691.9271273603901079.JavaMail.jira@thor> Date: Tue, 11 May 2010 14:51:41 -0400 (EDT) From: "Oleg Kalnichevski (JIRA)" To: dev@hc.apache.org Subject: [jira] Resolved: (HTTPCLIENT-938) Connection Timeout doesn't work where there's an UnknownHostException In-Reply-To: <27690677.3571273586023284.JavaMail.jira@thor> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/HTTPCLIENT-938?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Oleg Kalnichevski resolved HTTPCLIENT-938. ------------------------------------------ Resolution: Invalid Oz, This is a general limitation of the java platform we can do little about. In HttpClient 4.0 one can replace the standard DNS resolution code with a custom routine by using a custom ClientConnectionOperator. Oleg > 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.(Socket.java:367) > at java.net.Socket.(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