[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-2192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17460522#comment-17460522
 ] 

Martijn Brinkers commented on HTTPCLIENT-2192:
----------------------------------------------

Some additional information. If I catch all exceptions thrown by
future.get()
and continue, at some point an assertion fails (Endpoint is not connected) and 
the application hangs

 
{noformat}
java.util.concurrent.ExecutionException: java.lang.IllegalStateException: 
Endpoint is not connected
    at org.apache.hc.core5.concurrent.BasicFuture.getResult(BasicFuture.java:72)
    at org.apache.hc.core5.concurrent.BasicFuture.get(BasicFuture.java:85)
    at test.TestHTTP.main(TestHTTP.java:69)
Caused by: java.lang.IllegalStateException: Endpoint is not connected
    at org.apache.hc.core5.util.Asserts.check(Asserts.java:38)
    at 
org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$InternalConnectionEndpoint.getValidatedPoolEntry(PoolingAsyncClientConnectionManager.java:549)
    at 
org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$InternalConnectionEndpoint.execute(PoolingAsyncClientConnectionManager.java:596)
    at 
org.apache.hc.client5.http.nio.AsyncConnectionEndpoint.execute(AsyncConnectionEndpoint.java:99)
    at 
org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime.execute(InternalHttpAsyncExecRuntime.java:262)
    at 
org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec.execute(HttpAsyncMainClientExec.java:245)
    at 
org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
    at 
org.apache.hc.client5.http.impl.async.AsyncExecChainElement$1.proceed(AsyncExecChainElement.java:62)
    at 
org.apache.hc.client5.http.impl.async.AsyncConnectExec$1.completed(AsyncConnectExec.java:142)
    at 
org.apache.hc.client5.http.impl.async.AsyncConnectExec$1.completed(AsyncConnectExec.java:136)
    at 
org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime$1.completed(InternalHttpAsyncExecRuntime.java:114)
    at 
org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime$1.completed(InternalHttpAsyncExecRuntime.java:105)
    at 
org.apache.hc.core5.concurrent.BasicFuture.completed(BasicFuture.java:123)
    at 
org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$1$1.leaseCompleted(PoolingAsyncClientConnectionManager.java:286)
    at 
org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$1$1.completed(PoolingAsyncClientConnectionManager.java:271)
    at 
org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$1$1.completed(PoolingAsyncClientConnectionManager.java:235)
    at 
org.apache.hc.core5.concurrent.BasicFuture.completed(BasicFuture.java:123)
    at 
org.apache.hc.core5.pool.StrictConnPool.fireCallbacks(StrictConnPool.java:399)
    at org.apache.hc.core5.pool.StrictConnPool.lease(StrictConnPool.java:215)
    at 
org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$1.<init>(PoolingAsyncClientConnectionManager.java:232)
    at 
org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager.lease(PoolingAsyncClientConnectionManager.java:228)
    at 
org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime.acquireEndpoint(InternalHttpAsyncExecRuntime.java:100)
    at 
org.apache.hc.client5.http.impl.async.AsyncConnectExec.execute(AsyncConnectExec.java:135)
    at 
org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
    at 
org.apache.hc.client5.http.impl.async.AsyncExecChainElement$1.proceed(AsyncExecChainElement.java:62)
    at 
org.apache.hc.client5.http.impl.async.AsyncProtocolExec.internalExecute(AsyncProtocolExec.java:183)
    at 
org.apache.hc.client5.http.impl.async.AsyncProtocolExec.execute(AsyncProtocolExec.java:145)
    at 
org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
    at 
org.apache.hc.client5.http.impl.async.AsyncExecChainElement$1.proceed(AsyncExecChainElement.java:62)
    at 
org.apache.hc.client5.http.impl.async.AsyncHttpRequestRetryExec.internalExecute(AsyncHttpRequestRetryExec.java:97)
    at 
org.apache.hc.client5.http.impl.async.AsyncHttpRequestRetryExec.execute(AsyncHttpRequestRetryExec.java:180)
    at 
org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
    at 
org.apache.hc.client5.http.impl.async.AsyncExecChainElement$1.proceed(AsyncExecChainElement.java:62)
    at 
org.apache.hc.client5.http.impl.async.AsyncRedirectExec.internalExecute(AsyncRedirectExec.java:112)
    at 
org.apache.hc.client5.http.impl.async.AsyncRedirectExec.execute(AsyncRedirectExec.java:278)
    at 
org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
    at 
org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient.executeImmediate(InternalAbstractHttpAsyncClient.java:367)
    at 
org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient$1.sendRequest(InternalAbstractHttpAsyncClient.java:223)
    at 
org.apache.hc.core5.http.nio.support.BasicRequestProducer.sendRequest(BasicRequestProducer.java:93)
    at 
org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient.doExecute(InternalAbstractHttpAsyncClient.java:180)
    at 
org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:97)
    at 
org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:107)
    at 
org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:116)
    at test.TestHTTP.main(TestHTTP.java:63){noformat}

> ConnectionClosedException with CloseableHttpAsyncClient when repeatedly 
> downloading a file
> ------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-2192
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2192
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient (async)
>    Affects Versions: 5.1.2
>            Reporter: Martijn Brinkers
>            Priority: Major
>         Attachments: TestHTTPClient.zip, full-wire-log.txt
>
>
> If I download a file repeatedly using a single instance of 
> CloseableHttpAsyncClient, the following exception is thrown after few requests
> java.io.IOException: org.apache.hc.core5.http.ConnectionClosedException: 
> Connection is closed
> The following test app always ends up with a ConnectionClosedException after 
> a number of requests
> {code:java}
> public class TestHTTP
> {
>     public static void main(final String[] args) throws Exception
>     {
>         URI uri = new 
> URI("http://127.0.0.1:8000/crls/test-ca-no-next-update.crl";);
>         CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();
>         client.start();
>         try {
>             SimpleHttpRequest request = SimpleRequestBuilder.get(uri).build();
>             SimpleRequestProducer requestProducer = 
> SimpleRequestProducer.create(request);
>             SimpleResponseConsumer responseConsumer = 
> SimpleResponseConsumer.create();
>             FutureCallback<SimpleHttpResponse> callback = new 
> FutureCallback<SimpleHttpResponse>()
>             {
>                 @Override
>                 public void completed(final SimpleHttpResponse response) {
>                     System.out.println("************** completed");
>                     System.out.println(request + "->" + new 
> StatusLine(response));
>                     System.out.println(response.getBody());
>                 }
>                 @Override
>                 public void failed(final Exception ex) {
>                     System.out.println("************** failed");
>                     System.out.println(request + "->" + ex);
>                 }
>                 @Override
>                 public void cancelled() {
>                     System.out.println("************** canceled");
>                     System.out.println(request + " cancelled");
>                 }
>             };
>             for (int i = 0; i < 10000; i++)
>             {
>                 System.out.println("Request: " + i);
>                 Future<SimpleHttpResponse> future = client.execute(
>                         requestProducer,
>                         responseConsumer,
>                         callback);
>                 future.get();
>                 //if sleep is enabled, no exception will be thrown
>                 //Thread.sleep(1);
>             }
>         }
>         catch (ExecutionException e) {
>             e.printStackTrace();
>         }
>         finally {
>             client.close(CloseMode.GRACEFUL);
>         }
>     }
> }
> {code}
>  
> The full stack trace:
> {noformat}
> java.util.concurrent.ExecutionException: 
> org.apache.hc.core5.http.ConnectionClosedException: Connection is closed
>     at 
> org.apache.hc.core5.concurrent.BasicFuture.getResult(BasicFuture.java:72)
>     at org.apache.hc.core5.concurrent.BasicFuture.get(BasicFuture.java:85)
>     at test.TestHTTP.main(TestHTTP.java:65)
> Caused by: org.apache.hc.core5.http.ConnectionClosedException: Connection is 
> closed
>     at 
> org.apache.hc.core5.http.nio.command.CommandSupport.cancelCommands(CommandSupport.java:76)
>     at 
> org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onDisconnect(AbstractHttp1StreamDuplexer.java:409)
>     at 
> org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.disconnected(AbstractHttp1IOEventHandler.java:95)
>     at 
> org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.disconnected(ClientHttp1IOEventHandler.java:39)
>     at 
> org.apache.hc.core5.reactor.InternalDataChannel.disconnected(InternalDataChannel.java:193)
>     at 
> org.apache.hc.core5.reactor.SingleCoreIOReactor.processClosedSessions(SingleCoreIOReactor.java:231)
>     at 
> org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:133)
>     at 
> org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:85)
>     at 
> org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
>     at java.base/java.lang.Thread.run(Thread.java:829)
>  {noformat}
> The file that is downloaded is served by python http server running on 
> localhost:
> {code:java}
> python3 -m http.server{code}
> If I add Thread.sleep, the exception will not happen.
> For some reason it looks like the IOReactorWorker background thread closes 
> the CloseableHttpAsyncClient
> Any idea? 



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to