Category Archives: asynchttpclient connection reset by peer in asynchronous http client

I am using the Apache http asynchronous client library to make parallel HTTP calls and receive the response on a callback. I am getting the following error after my request when the code is deployed on the server. Connection reset by peer
    at Method)
    at org.apache.http.nio.reactor.ssl.SSLIOSession.receiveEncryptedData(
    at org.apache.http.nio.reactor.ssl.SSLIOSession.isAppInputReady(
    at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(
    at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(
    at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(
    at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$

here are my dependencies


how do I solve this? Thanks in advance.

Adding my code for reference

        CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().build();
        try {
            final HttpGet[] requests = new HttpGet[] {new HttpGet(""),
                    new HttpGet(""),
                    new HttpGet("")};
            final CountDownLatch latch = new CountDownLatch(requests.length);
            final LocationData location= new LocationData();
            for (final HttpGet request: requests) {
                request.addHeader("Authorization", "Bearer "+token);
                httpclient.execute(request, new FutureCallback<HttpResponse>() {

                    public void completed(final HttpResponse response) {


                            BufferedReader in = null;
                            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                            String data = null;

                            while((data =in.readLine())!= null)
                            //process the data

                    public void failed(final Exception ex) {
                        System.out.println(request.getRequestLine() + "->" + ex);

                    public void cancelled() {
                        System.out.println(request.getRequestLine() + " cancelled");

            try {
            } catch (InterruptedException e) {
            //some more processinng here 
                } catch (Exception e) {


Anyhelp would be appriciated. Anyone?

EDIT adding the logs from the server

status code | last accessed at             | api

200         | 2018-05-16 10:42:05.241000+0000 |  /api1
499         | 2018-05-16 10:42:05.290000+0000 | /api2
499         | 2018-05-16 10:42:05.416000+0000 |   /api3
200         | 2018-05-16 10:42:05.255000+0000 |  /api1
499         | 2018-05-16 10:42:05.415000+0000 | /api2
499         | 2018-05-16 10:42:05.425000+0000 |   /api3
499         | 2018-05-16 10:42:05.416000+0000 |  /api1
200         | 2018-05-16 10:42:05.256000+0000 | /api2
499         | 2018-05-16 10:42:05.460000+0000 |   /api3

Apache HttpAsyncClient thread count configuration

I'm trying to use AsyncRestTemplate with custom Apache HttpAsyncClient.

First i used simple new AsyncRestTemplate(); And when i added logs with thread name to future callback i saw that all of them was different (SimpleAsyncTaskExecutor-1..n).

Later i needed to implement custom ssl logic in my AsyncRestTemplate, so i added HttpComponentsAsyncClientHttpRequestFactory to constructor.

Then i had some issues in my BL so i started to debug and saw that only two threads was used in future callback I/O dispatcher 1 and I/O dispatcher 2.

I tried to use this configuration but i still have only two threads.

return new AsyncRestTemplate(
       new HttpComponentsAsyncClientHttpRequestFactory(

What i'm doing wrong?

Apache Http HttpAsyncClient NoClassDefFoundError

I'm using apache http async client library in order to create async http requests.

added to my maven dependencies:


My code is using HttpAsyncClientBuilder in order to build the client. In runtime I get an exception

java.lang.NoClassDefFoundError: org/apache/http/conn/util/PublicSuffixMatcherLoader

It seems that this jar is missing some dependencies. Any advice?

Not getting response with Http Async Client

I am stuck with this weird situation where sometimes my HTTP requests don't go out or I don't get a HTTP response to my request sporadically. My application makes several (100s) http requests to other 3rd party service periodically most of which work absolutely fine. I use the CloseableHttpAsyncClient (Version 4.0) with a custom HttpRequestIntercerptor and HttpResponseInterceptor. These were mainly added for debugging purpose with the RequestInterceptor is the last interceptor in the chain and the ResponseInterceptor is the first one. The idea was to log each http request at the last stage before it sends the actual request and to log each http response when it is first received.

I have the following pattern to setup the async client:

    HttpAsyncClientBuilder asyncClientBuilder = HttpAsyncClientBuilder.create();
    asyncClientBuilder.addInterceptorLast(new MyHttpRequestInterceptor());
    asyncClientBuilder.addInterceptorFirst(new MyHttpResponseInterceptor());
    IOReactorConfig reactorConfig = IOReactorConfig.DEFAULT;

    reactorConfig.setConnectTimeout(5 * 60 * 1000); // 5 mins 
    reactorConfig.setSoTimeout(5 * 60 * 1000); // 5 mins
    System.setProperty("http.maxConnections", "100");

    this.asyncHttpClient = asyncClientBuilder.useSystemProperties().build();

To make the request I do:

HttpGet httpGet = new HttpGet("some url");
asyncHttpClient.execute(httpGet, new AsyncHTTPResponseHandler(requestMetadata));

Here is my AsyncHTTPResponseHandler class:

class AsyncHTTPResponseHandler implements FutureCallback<HttpResponse> {

    // local copy of the request for reference while processing the response.
    private RequestMetadata requestMetadata;

    public AsyncHTTPResponseHandler(final RequestMetadata requestMetadata) {
        Thread.currentThread().setUncaughtExceptionHandler(new HttpUncaughtExceptionHandler(requestMetadata));

    public void cancelled() {
        logger.error("AsyncHTTPResponseHandler#Http request id: {} cancelled",

    public void completed(HttpResponse response) {
        logger.debug("Received HTTP Response for request id: {}",
        //handleHttpResponse(requestMetadata, response);

    public void failed(Exception e) {
        logger.error("AsyncHTTPResponseHandler#Error in Http request id: " + requestMetadata.getRequestId(), e);


Based on this setup, I see the following cases based on my interceptors logs: 1. My application http request triggers an asyncclient HttpRequest and I get the HttpResponse -- Success. 2. My application http request triggers an asyncclient HttpRequest (the interceptor logs it) and I don't get the HttpResponse for this request --- Don't know why? 3. My application http request does not trigger an asyncclient HttpRequest (the interceptor does not log it) and I don't get the HttpResponse for this request --- Don't know why?

Any tips or suggestions on what I can do fix this or debug this problem further?