[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16944514#comment-16944514 ] ASF subversion and git services commented on HTTPCLIENT-2013: - Commit d5e1392840fcbd9ff9d9c5b19d8ed9da2883c224 in httpcomponents-client's branch refs/heads/JDK-8212885 from Oleg Kalnichevski [ https://gitbox.apache.org/repos/asf?p=httpcomponents-client.git;h=d5e1392 ] HTTPCLIENT-2013: revised handling of connect exceptions; improved consistency in behavior of the classic and async clients; ConnectTimeoutException now extends SocketTimeoutException > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Improvement > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Minor > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) > at java.net.Socket.connect(Socket.java:589) > at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) > at > org.apache.http.conn.ssl.SSLConnectionSocket
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16922837#comment-16922837 ] Chanseok Oh commented on HTTPCLIENT-2013: - Filed a bug against Oracle JDK a while ago. Just got a message today that they've finished internal review on it, and the bug has been posted today: [https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8230528] Their first comment is what I actually anticipated, since it's obvious {{SocketTimeoutException}} is when by the socket {{SO_TIMEOUT,}} while the {{ConnectException}} timeout case is when the handshake fails at a lower level unrelated to {{SO_TIMEOUT}}. In any case, the situation is confusing enough IMO and it doesn't provide a reliable way to programmatically determine whether a timeout happened, so I'll just hope they are willing to mitigate this somehow. Their priority is P4 though. > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Improvement > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Minor > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(Abstra
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16915209#comment-16915209 ] ASF subversion and git services commented on HTTPCLIENT-2013: - Commit d5e1392840fcbd9ff9d9c5b19d8ed9da2883c224 in httpcomponents-client's branch refs/heads/master from Oleg Kalnichevski [ https://gitbox.apache.org/repos/asf?p=httpcomponents-client.git;h=d5e1392 ] HTTPCLIENT-2013: revised handling of connect exceptions; improved consistency in behavior of the classic and async clients; ConnectTimeoutException now extends SocketTimeoutException > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Improvement > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Minor > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) > at java.net.Socket.connect(Socket.java:589) > at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) > at > org.apache.http.conn.ssl.SSLConnectionSocketFacto
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16915095#comment-16915095 ] ASF subversion and git services commented on HTTPCLIENT-2013: - Commit d5e1392840fcbd9ff9d9c5b19d8ed9da2883c224 in httpcomponents-client's branch refs/heads/development from Oleg Kalnichevski [ https://gitbox.apache.org/repos/asf?p=httpcomponents-client.git;h=d5e1392 ] HTTPCLIENT-2013: revised handling of connect exceptions; improved consistency in behavior of the classic and async clients; ConnectTimeoutException now extends SocketTimeoutException > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Improvement > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Minor > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) > at java.net.Socket.connect(Socket.java:589) > at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) > at > org.apache.http.conn.ssl.SSLConnectionSocket
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914970#comment-16914970 ] Chanseok Oh commented on HTTPCLIENT-2013: - Great. Keep up with the good work. > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Improvement > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Minor > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) > at java.net.Socket.connect(Socket.java:589) > at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) > at > org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:251) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:118) > ... 10 more > {code} > > -- This message was sent by Atlassian Jira (v8.3.2#803003) - To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914957#comment-16914957 ] Oleg Kalnichevski commented on HTTPCLIENT-2013: --- I revisited connect exception handling code in master and cleaned up things making sure that all classic and async client implementations handle connect failures the same way. [https://github.com/apache/httpcomponents-client/commit/e0c1c140d574872ba20574edd6eb941cc072d761] At the same time I found that the actual logic in 4.5 and 5.0 was reasonable and decided to not make any major changes (other than making {{ConnectTimeoutException}} extend {{SocketTimeoutException}} and eliminating unnecessary exception chaining). Most of the time JREs do the right thing and throw {{SocketTimeoutException}}. If for whatever reason some JREs decide to throw {{ConnectException}} instead, HttpClient will make an effort to correct it but it is still just guess-work based on exception message text. [~francium25] The only way of fixing the problem properly is to fix it as the source. So, I am sure you will be right on track reporting this issue to OpenJDK. Oleg — java version "1.7.0_75" Java(TM) SE Runtime Environment (build 1.7.0_75-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode) {noformat} Exception in thread "main" org.apache.hc.client5.http.ConnectTimeoutException: Connect to http://httpbin.org:80 [httpbin.org/52.22.188.80, httpbin.org/3.223.234.9] failed: connect timed out at org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:160) at org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:409) at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:164) at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:174) at org.apache.hc.client5.http.impl.classic.ConnectExec.execute(ConnectExec.java:135) at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) at org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) at org.apache.hc.client5.http.impl.classic.ProtocolExec.execute(ProtocolExec.java:165) at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) at org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) at org.apache.hc.client5.http.impl.classic.RetryExec.execute(RetryExec.java:88) at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) at org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) at org.apache.hc.client5.http.impl.classic.RedirectExec.execute(RedirectExec.java:116) at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) at org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57) at org.apache.hc.client5.http.impl.classic.ContentCompressionExec.execute(ContentCompressionExec.java:128) at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51) at org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:178) at org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:77) at org.apache.hc.client5.http.examples.QuickStart.main(QuickStart.java:55) Caused by: java.net.SocketTimeoutException: connect timed out at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:579) at org.apache.hc.client5.http.socket.PlainConnectionSocketFactory$1.run(PlainConnectionSocketFactory.java:87) at java.security.AccessController.doPrivileged(Native Method) at org.apache.hc.client5.http.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:84) at org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:152) ... 20 more {noformat} java version "1.8.0_181" Java(TM) SE Runtime Environment (build 1.8.0_181-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode) {noformat} E
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914952#comment-16914952 ] ASF subversion and git services commented on HTTPCLIENT-2013: - Commit e0c1c140d574872ba20574edd6eb941cc072d761 in httpcomponents-client's branch refs/heads/development from Oleg Kalnichevski [ https://gitbox.apache.org/repos/asf?p=httpcomponents-client.git;h=e0c1c14 ] HTTPCLIENT-2013: revised handling of connect exceptions; improved consistency in behavior of the classic and async clients; ConnectTimeoutException now extends SocketTimeoutException > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Improvement > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Minor > Fix For: 5.0 Beta6 > > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) > at java.net.Socket.connect(Socket.java:589) > at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) > at > org.apach
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914696#comment-16914696 ] Chanseok Oh commented on HTTPCLIENT-2013: - Agreed. Now you seem to be on track, great. Thanks! > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Improvement > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Minor > Fix For: 5.0 Beta6 > > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) > at java.net.Socket.connect(Socket.java:589) > at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) > at > org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:251) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:118) > ... 10 more > {code} > > -- This message was sent by Atlassian Jira (v8.3.2#803003) - To
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914682#comment-16914682 ] Oleg Kalnichevski commented on HTTPCLIENT-2013: --- To make matters worse they cannot even keep exception messages consistent. Sometime it is "Connection timed out" sometimes it is "Connection timed out (Connection timed)". Oleg > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Improvement > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Minor > Fix For: 5.0 Beta6 > > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) > at java.net.Socket.connect(Socket.java:589) > at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) > at > org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:251) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:118) > ... 10 more > {code} >
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914676#comment-16914676 ] Oleg Kalnichevski commented on HTTPCLIENT-2013: --- [~francium25] You are twisting the facts. The problem arises from the inconsistent behavior in some JREs that should be throwing {{SocketTimeoutException}} to signal operation timeout as per javadoc of [Socket#connect|https://docs.oracle.com/javase/7/docs/api/java/net/Socket.html#connect(java.net.SocketAddress,%20int)] but throw {{ConnectException}} instead, for whatever reason . HttpClient 4.x merely tries to compensate for that. Oleg > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Major > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) > at java.net.Socket.connect(Socket.java:589) > at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) > at > org.apache.http.conn.ssl.SS
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914537#comment-16914537 ] Oleg Kalnichevski commented on HTTPCLIENT-2013: --- [~francium25] HttpClient has been catching {{SocketTimeoutException}} and re-throwing those that occur in {{Socket#connect}} since 2006 because at that time there was no other way to distinguish genuine socket timeout from connect timeouts. At some later point (around 2013) someone at Oracle (or even Sun at that time) decided to start throwing {{ConnectException}} with newer versions of JRE instead. What HttpClient was trying to do was to make those exceptional conditions look consistent to the caller. I do not think we should change the behavior that many other users have come to depend on simply because you have decided to upgrade your dependencies. What I can do, though, is to revisit the whole thing in 5.0 where we are still at liberty to break compatibility with 4.x code line. Oleg > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Major > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddres
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914500#comment-16914500 ] Chanseok Oh commented on HTTPCLIENT-2013: - What I am saying is that, you catch {{ConnectException}}, but obviously you don't always re-throw it as {{HttpHostConnectException}}, according to the current code. Based on the actual exception message of the caught {{ConnectException}}, you sometimes (are supposed to) throw {{ConnectTimeoutException}}, which is not {{ConnectException}}. And this is triggered only when the exception is precisely {{Connection timed out}}, which is obviously for the connection timeout case. I am saying that now this is not happening here. If you are to say the current behavior is correct, I think it should rather be than you should really take out the following useless/incorrect/dangerous code to check the exception message. {code:java} throw "Connection timed out".equals(msg) ? ... : ... {code} > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Major > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketIm
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914490#comment-16914490 ] Chanseok Oh commented on HTTPCLIENT-2013: - Also note again that you DO catch {{java.net.ConnectException}} {code:java} } catch (final ConnectException ex) { if (last) { {code} and then you (are supposed to) throw {{ConnectTimeoutExcepton}} if the message is {{Connection timed out}}, which does not extend {{ConnectException}}. {code:java} throw "Connection timed out".equals(msg) ? new ConnectTimeoutException(ex, host, addresses) {code} > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Major > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) > at java.net.Socket.connect(Socket.java:589) > at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) > at > org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSo
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914487#comment-16914487 ] Chanseok Oh commented on HTTPCLIENT-2013: - Ok, to understand this with absolutely zero ambiguity, please let me confirm this: What you are saying is that it is the bug in Oracle / OpenJDK that the exception message of {{java.net.ConnectException}} should be {code:java} Connection timed out {code} instead of {code:java} Connection timed out (Connection timed out) {code} ? > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Major > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) > at java.net.Socket.connect(Socket.java:589) > at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) > at > org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:251) > at > org.apache.http.impl.conn.HttpClie
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914478#comment-16914478 ] Oleg Kalnichevski commented on HTTPCLIENT-2013: --- [~francium25] No, it does not (No, it does not). Please report this issue to Oracle / OpenJDK. Oleg > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Major > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) > at java.net.Socket.connect(Socket.java:589) > at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) > at > org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:251) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:118) > ... 10 more > {code} > > -- This message was sent by Atlassian Jira (v8.3.2#803003) -
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914472#comment-16914472 ] Chanseok Oh commented on HTTPCLIENT-2013: - It is rue that the Java runtime throws {{ConnectionException}} with the message {{Connection timed out (Connection timed out)}}. Now please look at the Apache code again I showed you in the bug description carefully. {code:java} } catch (final ConnectException ex) { if (last) { final String msg = ex.getMessage(); throw "Connection timed out".equals(msg) ? new ConnectTimeoutException(ex, host, addresses) : new HttpHostConnectException(ex, host, addresses); } {code} As I said, the intention is obviously to throw {{ConnectTimeoutException}} in this case instead of {{HttpHostConnectException}} when the exception message is {{Connection timed out}}. However, this is not happening. So, the bug is that {{DefaultHttpClientConnectionOperator}} does not throw {{ConnectTimeoutException}}. It should not re-throw it as {{HttpHostConnectException}} but as {{ConnectTimeoutException}}. Does this make it clear? > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Major > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnec
[jira] [Commented] (HTTPCLIENT-2013) Connect timeout throws HttpHostConnectException (ConnectException) instead of ConnectTimeoutException (IOException)
[ https://issues.apache.org/jira/browse/HTTPCLIENT-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914000#comment-16914000 ] Oleg Kalnichevski commented on HTTPCLIENT-2013: --- [~francium25] Java runtime throws {{java.net.ConnectException}}, HttpClient catches it and re-throws it as {{HttpHostConnectException}} which is a subclass of {{java.net.ConnectException}}. So, what is exactly the bug you are reporting here? Oleg > Connect timeout throws HttpHostConnectException (ConnectException) instead of > ConnectTimeoutException (IOException) > --- > > Key: HTTPCLIENT-2013 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2013 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient (classic) >Affects Versions: 4.5.9 > Environment: Linux > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) >Reporter: Chanseok Oh >Priority: Major > > It is obvious from the code in DefaultHttpClientConnectionOperator that it is > supposed to throw ConnectTimeoutException in the case of connection timeout: > {code:java} > } catch (final ConnectException ex) { > if (last) { > final String msg = ex.getMessage(); > throw "Connection timed out".equals(msg) > ? new ConnectTimeoutException(ex, host, addresses) > : new HttpHostConnectException(ex, host, addresses); > } > {code} > Recently, we've upgraded Apache HttpClient (indirectly through Google HTTP > Client), and our production code handling ConnectionException got broken due > to DefaultHttpClientConnectionOperator throwing HttpHostConnectException that > extends ConnectionException. (OTOH, ConnectTimeoutException is an IOException > and not a ConnectionException.) > Java version: > {code} > openjdk version "1.8.0_222" > OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1-b10) > OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) > {code} > Example code to reproduce: > {code:java} > public static void main(String[] args) throws IOException { >// example.com is reserved by the DNS standard and will always trigger > timeout >try (CloseableHttpClient client = HttpClients.createDefault(); >CloseableHttpResponse response = client.execute(new > HttpGet("https://example.com:81";))) {} > } > {code} > It currently throws the other exception HttpHostConnectException rather than > the supposed ConnectTimeoutException. > {code} > Exception in thread "main" org.apache.http.conn.HttpHostConnectException: > Connect to example.com:81 [example.com/93.184.216.34, > example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out > (Connection timed out) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138) > at > org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) > at > org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357) > at > org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218) > at > org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194) > at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85) > at > org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) > at > org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) > at > org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) > at com.example.ApacheHttpClient2.main(ApacheHttpClient2.java:13) > Caused by: java.net.ConnectException: Connection timed out (Connection timed > out) > at java.net.PlainSocketImpl.socketConnect(Native Method) > at > java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) > at > java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) > at > java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) > at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) > at java.net.Socket.connect(Socket.java:589) > at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) > at > org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:251) > at > org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:118) >