hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Francois-Xavier Bonnet (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPCLIENT-1328) socketTimeout parameter is ignored
Date Fri, 22 Feb 2013 16:58:13 GMT

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

Francois-Xavier Bonnet commented on HTTPCLIENT-1328:
----------------------------------------------------

I have already fixed it but I will write a unit test before committing.
                
> socketTimeout parameter is ignored
> ----------------------------------
>
>                 Key: HTTPCLIENT-1328
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1328
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.3 Alpha1
>            Reporter: Francois-Xavier Bonnet
>
> RequestConfig.custom().setSocketTimeout(1000) is ignored if the connection is a new connection
but works if the connection has been kept alive from a previous request.
> I have got a page that takes 8 s to respond. This code should fail at first request after
1 s:
> 		CloseableHttpClient httpClient = HttpClients.custom().build();
> 		HttpGet request = new HttpGet("http://localhost:8080/slow.jsp");
> 		request.setConfig(RequestConfig.custom().setSocketTimeout(1000).build());
> 		long start = System.currentTimeMillis();
> 		// Should fail with socket timeout!
> 		EntityUtils.consume(httpClient.execute(request).getEntity());
> 		System.out.println("First request executed in " + (System.currentTimeMillis() - start)
+ " ms");
> 		request = new HttpGet("http://localhost:8080/slow.jsp");
> 		request.setConfig(RequestConfig.custom().setSocketTimeout(1000).build());
> 		start = System.currentTimeMillis();
> 		// Should fail with socket timeout!
> 		EntityUtils.consume(httpClient.execute(request).getEntity());
> 		System.out.println("Second request executed in " + (System.currentTimeMillis() - start)
+ " ms");
> I get this output:
> First request executed in 8115 ms
> Exception in thread "main" java.net.SocketTimeoutException: Read timed out
> 	at java.net.SocketInputStream.socketRead0(Native Method)
> 	at java.net.SocketInputStream.read(SocketInputStream.java:129)
> 	at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:130)
>         ...
> The first request does not respect the timeout but the second does. This comes from this
code in org.apache.http.impl.execchain.MainClientExec.execute(HttpRoute, HttpRequestWrapper,
HttpClientContext, HttpExecutionAware):
>                 if (!managedConn.isOpen()) {
>                     this.log.debug("Opening connection " + route);
>                     try {
>                         establishRoute(proxyAuthState, managedConn, route, request, context);
>                     } catch (final TunnelRefusedException ex) {
>                         if (this.log.isDebugEnabled()) {
>                             this.log.debug(ex.getMessage());
>                         }
>                         response = ex.getResponse();
>                         break;
>                     }
>                 } else {
>                     final int timeout = config.getSocketTimeout();
>                     if (timeout >= 0) {
>                         managedConn.setSocketTimeout(timeout);
>                     }
>                 }
> The socket timeout is set only if the connection is already open.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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


Mime
View raw message