hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rob Burke <Rob.Bu...@imc-chicago.com>
Subject HttpClient code blocks until remote server is killed
Date Fri, 25 Jul 2014 16:24:37 GMT

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/] 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()
            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 {

I am hoping this is a simple oversight in my construction of the HttpClient.

Any and all ideas/suggestions is greatly appreciated!



The information in this e-mail is intended only for the person or entity to which it is addressed.

It may contain confidential and /or privileged material. If someone other than the intended
recipient should receive this e-mail, he / she shall not be entitled to read, disseminate,
disclose or duplicate it.

If you receive this e-mail unintentionally, please inform us immediately by "reply" and then
delete it from your system. Although this information has been compiled with great care, neither
IMC Financial Markets & Asset Management nor any of its related entities shall accept
any responsibility for any errors, omissions or other inaccuracies in this information or
for the consequences thereof, nor shall it be bound in any way by the contents of this e-mail
or its attachments. In the event of incomplete or incorrect transmission, please return the
e-mail to the sender and permanently delete this message and any attachments.

Messages and attachments are scanned for all known viruses. Always scan attachments before
opening them.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message