On Fri, 2014-07-25 at 16:24 +0000, Rob Burke wrote:
> Hello,
>
> I have been facing issues with the HttpClient around resiliency to
> server-side failures. My intention is that if my Http request isn't
> satisfied in some small amount of time (say 600ms), then HttpClient should
> give up.
>
> I thought that I was achieving this by setting connectionTimeout in the
> RequestConfig. Today we ran into a situation where we blocked indefinitely
> in httpClient. I finally killed the server it was connecting to, and my
> HttpClient requesting code (below) finally throws an IOException.
>
> Our logging was empty until I killed the remote server. Once it was down,
> the client logged:
>
> 10:36:15.712 [ServiceRunnerThread] INFO o.a.http.impl.execchain.RetryExec -
> I/O exception (org.apache.http.NoHttpResponseException) caught when
> processing request to {}->http://remotehost:8888<http://remotehost:8888/>:
> The target server failed to respond
> 10:36:15.713 [ServiceRunnerThread] INFO o.a.http.impl.execchain.RetryExec -
> Retrying request to {}->http://remotehost:8888<http://remotehost:8888/>
> 10:36:15.768 [ServiceRunnerThread] ERROR c.i.g.s.b.o.m.DataService -
> Exception while attempting to connect to Remote Gateway:
> org.apache.http.conn.HttpHostConnectException: Connect to remote host:8888
> [remotehost/10.1.1.1] failed: Connection refused
>
>
> Here is my request logic. I am using httpclient-4.3.3:
>
> final HttpGet myRequest = new HttpGet(aUri);
>
> try {
> RequestConfig myRequestConfig =
> RequestConfig.custom().setConnectTimeout(CONNECTION_TIMEOUT).build();
> CloseableHttpClient myClient = HttpClientBuilder.create()
> .setDefaultRequestConfig(myRequestConfig)
> .build();
> final HttpResponse myResponse = myClient.execute(myRequest);
> final HttpEntity myEntity = myResponse.getEntity();
>
> if (myEntity == null) {
> return null;
> }
>
> final String myContent = EntityUtils.toString(myEntity);
> if (ok(myResponse)) {
> return theObjectMapper.readValue(myContent, aClass);
> } else {
> LOGGER.error("{}", myContent);
> return null;
> }
> } finally {
> myRequest.releaseConnection();
> }
>
>
> I am hoping this is a simple oversight in my construction of the HttpClient.
>
>
> Any and all ideas/suggestions is greatly appreciated!
>
It looks like the server succeeded in accepting an incoming connection
within the given timeout (CONNECTION_TIMEOUT) but failed to send back
any data. Please also make sure that you set a socket (read) timeout.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]