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

Luca Cavanna commented on HTTPCORE-587:
---------------------------------------


Hi [~olegk], I can reproduce this error. Yet I wonder if I may be misusing the 
client as I am reusing the same request throughout multiple executions of it, 
by calling reset on it before each execution. This has worked out fine until 
now (that's how we use the http async client in the official java client for 
Elasticsearch). We are encountering problems as we recently exposed the ability 
to cancel requests. Here is a code snippet that breaks at almost every run:

{code:java}
        HttpServer httpServer = HttpServer.create(new 
InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
        httpServer.start();
        httpServer.createContext("/test", exchange -> {
            exchange.sendResponseHeaders(200, 0);
            exchange.close();
        });
        HttpHost httpHost = new 
HttpHost(httpServer.getAddress().getHostString(), 
httpServer.getAddress().getPort());
        try (CloseableHttpAsyncClient client = 
HttpAsyncClientBuilder.create().build()) {
            client.start();
            HttpGet httpGet = new HttpGet("/test");
            for (int i = 0; i < 10000; i++) {
                httpGet.reset();
                Future<HttpResponse> future = client.execute(httpHost, httpGet, 
null);
                httpGet.abort();
                try {
                    future.get();
                    assert false;
                } catch(CancellationException e) {
                    //expected
                }
            }
        } finally {
            httpServer.stop(0);
        }
{code} 

 I am curious to hear your thoughts on this. 

> Connection must be created by connection manager issue
> ------------------------------------------------------
>
>                 Key: HTTPCORE-587
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-587
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>          Components: HttpCore, HttpCore NIO
>    Affects Versions: 4.4.11
>            Reporter: Pranav Arora
>            Priority: Major
>
> This is the same issue that is discussed in HTTPCORE-370 and HTTPCORE-574. I 
> am facing the following exception:
>  
>  
> {code:java}
> [ERROR] [] 2019-07-29 09:33:10.639 [pool-2-thread-1] InternalHttpAsyncClient 
> - I/O reactor terminated abnormally
> org.apache.http.nio.reactor.IOReactorException: I/O dispatch worker 
> terminated abnormally
> at 
> org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:356)
> at 
> org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
> at 
> org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
> at java.lang.Thread.run(Thread.java:748) [?:1.8.0_141]
> Caused by: java.lang.IllegalStateException: Connection must be created by 
> connection manager
> at 
> org.apache.http.impl.nio.client.InternalIODispatch.createConnection(InternalIODispatch.java:56)
> at 
> org.apache.http.impl.nio.client.InternalIODispatch.createConnection(InternalIODispatch.java:39)
> at 
> org.apache.http.impl.nio.reactor.AbstractIODispatch.connected(AbstractIODispatch.java:70)
> at 
> org.apache.http.impl.nio.reactor.BaseIOReactor.sessionCreated(BaseIOReactor.java:248)
> at 
> org.apache.http.impl.nio.reactor.AbstractIOReactor.processNewChannels(AbstractIOReactor.java:427)
> at 
> org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:287)
> 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)
> ... 1 more{code}
>  
> This occurs randomly during production and I have not been able to reproduce 
> it locally. What I instead tried was pass a custom exception handler. 
>  
>  
> {code:java}
> public class CustomExceptionHandler implements IOReactorExceptionHandler {
>  @Override
>  public boolean handle(IOException ex) {
>   log.error("I/O Reactor IO exception", ex);
>   return false;
>  }
>  @Override
>  public boolean handle(RuntimeException ex) {
>   log.error("I/O Reactor Runtime Exception", ex);
>   if (ex instanceof IllegalStateException) {
>    throw new CancelledKeyException();
>   }
>   return false;
>  }
> }
> {code}
>  
>  
> It helped for the above exception as it did not lead to immediate shutdown of 
> I/O Reactor but now I am facing a different issue.
>  
>  
> {code:java}
> [ERROR] [] 2019-07-30 18:22:37.684 [pool-2-thread-1] InternalHttpAsyncClient 
> - I/O reactor terminated abnormally
> java.lang.NullPointerException: null
> at 
> <packageNameTruncated>.DefaultConnectingIOReactorTemp.processEvent(DefaultConnectingIOReactorTemp.java:158)
> at 
> <packageNameTruncated>.DefaultConnectingIOReactorTemp.processEvents(DefaultConnectingIOReactorTemp.java:136)
> at 
> org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351)
> at 
> org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
> at 
> org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
> at java.lang.Thread.run(Thread.java:748)
> {code}
>  
>  
> DefaultConnectingIOReactorTemp is exactly the same as 
> DefaultConnectingIOReactor with the added code that was intended to fix 
> HTTPCORE-370. The corresponding line in DefaultConnectingIOReactor is 167 
> (final SessionRequestImpl sessionRequest = 
> requestHandle.getSessionRequest()). The added code is this: 
> https://github.com/ok2c/httpcore/commit/aa812282f26fdd1975233a892c5405fa0da781b4#diff-d577e717cb1e97f3a3c0adbc8d563062
>  



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

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

Reply via email to