java.io.IOException connection reset by peer in asynchronous http client

684 views
Skip to first unread message

Jayesh Tripathi

unread,
May 28, 2018, 8:33:15 AM5/28/18
to asynchttpclient

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.


java.io.IOException: Connection reset by peer

    at sun.nio.ch.FileDispatcherImpl.read0(Native Method)

    at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)

    at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)

    at sun.nio.ch.IOUtil.read(IOUtil.java:197)

    at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:384)

    at org.apache.http.nio.reactor.ssl.SSLIOSession.receiveEncryptedData(SSLIOSession.java:450)

    at org.apache.http.nio.reactor.ssl.SSLIOSession.isAppInputReady(SSLIOSession.java:504)

    at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:120)

    at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)

    at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)

    at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)

    at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)

    at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)

    at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588)

    at java.lang.Thread.run(Thread.java:745)


here are my dependencies


<dependency>

        <groupId>org.apache.httpcomponents</groupId>

        <artifactId>httpasyncclient</artifactId>

        <version>4.1.3</version>

    </dependency>

    <dependency>

      <groupId>org.apache.httpcomponents</groupId>

      <artifactId>httpclient</artifactId>

      <version>4.5.5</version>

    </dependency>

    <dependency>

        <groupId>org.apache.httpcomponents</groupId>

        <artifactId>httpcore</artifactId>

        <version>4.4</version>

    </dependency>


Adding my code for reference


        CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().build();

        try {

            httpclient.start();

            final HttpGet[] requests = new HttpGet[] {new HttpGet("https://www.api.com/api/api1"),

                    new HttpGet("https://www.api.com/api/api2"),

                    new HttpGet("https://www.api.com/api/api3")};

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


                    @Override

                    public void completed(final HttpResponse response) {


                        latch.countDown();


                            BufferedReader in = null;

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

                            String data = null;


                            while((data =in.readLine())!= null)

                            {

                            //process the data

                            }

                    }



                    @Override

                    public void failed(final Exception ex) {

                        latch.countDown();

                        System.out.println(request.getRequestLine() + "->" + ex);

                        ex.printStackTrace();

                    }


                    @Override

                    public void cancelled() {

                        latch.countDown();

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

                    }


                });

            }

            try {

                latch.await();

            } catch (InterruptedException e) {

                e.printStackTrace();

            }

            //some more processinng here 

                } catch (Exception e) {

                    e.printStackTrace();

                }

            }


        } 



the access logs from the nginx 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


how do I solve this? Thanks in advance.


Stéphane LANDELLE

unread,
May 28, 2018, 9:46:34 AM5/28/18
to asyncht...@googlegroups.com
Here is the mailing list of https://github.com/AsyncHttpClient/async-http-client.
It has nothing to do with Apache HttpComponents.

Stéphane Landelle
GatlingCorp CEO


--
You received this message because you are subscribed to the Google Groups "asynchttpclient" group.
To unsubscribe from this group and stop receiving emails from it, send an email to asynchttpclient+unsubscribe@googlegroups.com.
To post to this group, send email to asynchttpclient@googlegroups.com.
Visit this group at https://groups.google.com/group/asynchttpclient.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages