11

we have three applications A,B and C deployed on same tomcat server.There is an HTTP call that happens between A to B(REST CALL) and Another http call from B to C(REST CALL)

We were using synchronous HTTP call initially,recently we changed our code to Asynchronous call. We have used HttpAsyncClients for (Application A to call Application B) and for (Application B to call Application C)..

we are getting intermittent org.apache.http.ConnectionClosedException: Some time we are getting this exception in Logs of application A(Async Client to B) and some time in Application B(Async Client to C)

 CloseableHttpAsyncClient  client = HttpAsyncClients.custom()
                    .setMaxConnPerRoute(100))
                    .setMaxConnTotal(config.getInt(150)).build();

and for Every request we gave timeout of

final RequestConfig params = RequestConfig.custom().setConnectTimeout(300000) // 5min
                    .setSocketTimeout(300000).setConnectionRequestTimeout(300000).build();

Please find the stack trace below:

   org.apache.http.ConnectionClosedException: Connection closed
        at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.endOfInput(HttpAsyncRequestExecutor.java:344) [httpcore-nio-4.4.5.jar:4.4.5]
        at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:261) [httpcore-nio-4.4.5.jar:na]
        at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81) [httpasyncclient-4.1.2.jar:na]
        at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39) [httpasyncclient-4.1.2.jar:na]
        at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114) [httpcore-nio-4.4.5.jar:4.4.5]
        at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162) [httpcore-nio-4.4.5.jar:4.4.5]
        at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337) [httpcore-nio-4.4.5.jar:4.4.5]
        at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) [httpcore-nio-4.4.5.jar:4.4.5]
        at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276) [httpcore-nio-4.4.5.jar:4.4.5]
        at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) [httpcore-nio-4.4.5.jar:4.4.5]
        at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588) [httpcore-nio-4.4.5.jar:4.4.5]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]

Please Note this question is not duplicate of Intermittent ConnectionClosedException with httpasynclient stacj trace is completely different..And event this issue happens intermittent.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
svs teja
  • 957
  • 2
  • 22
  • 43
  • https://issues.apache.org/jira/browse/HTTPCORE-414 might be helpful? – wcy Dec 18 '16 at 14:24
  • I run into the same problem, and finally I found I set a wrong header value and the server close the connection. – wcy Dec 18 '16 at 14:33
  • @wcy Could you elaborate please? I'm having the same issue with the exact same stack trace... – Olivier Gérardin Mar 26 '19 at 15:49
  • How did you solve it ? I'm facing exactly same error – jAvA Jan 26 '20 at 20:57
  • This is not a client issue, the remote server is terminating the connection. If you wish, work with the remote server's owner(s) to debug why connections are getting closed from their end, but know that from a technical perspective, this is a normal event. Your code needs to be able to handle sudden errors while networking. – AndrewF Feb 16 '22 at 06:52

0 Answers0