28

I have a service that is expected to execute requests at ~5 or more requests/min. This service depends on Apache AsyncHttpClient. After every few minutes, the clients hits some condition which causes java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED. All requests to the client start failing with same exception message. After service is restarted, this cycle repeats.

It is really hard to debug this problem as the request execution failure surprisingly does not cause a callback to the failed() method of the AsyncResponse.

From what I could gather, there has been a fix HTTPCORE-370 in HttpCore NIO which solved a similar problem in 4.3.2. I am using the following version -

commons-httpclient-3.1.jar
httpasyncclient-4.1.1.jar
httpcore-4.4.4.jar
httpcore-nio-4.4.4.jar

Yet seeing this problem.

4

4 回答 4

10

我一直在我的应用程序中处理同样的异常,我终于从这篇文章中找到了一个有用的建议 - http://httpcomponents.10934.n7.nabble.com/IO-reactor-status-STOPPED-td29059.html

您可以使用 I/O 反应器的 #getAuditLog() 方法来准确找出导致它终止的异常。

如果您保留对 ConnectionManager 的 IOReactor 的引用,则可以调用此方法来深入了解实际问题:

http://hc.apache.org/httpcomponents-core-4.4.x/httpcore-nio/apidocs/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.html#getAuditLog()

原来我在自己的代码中做了一些非常愚蠢的事情。但是直到我阅读了审计日志,我才弄明白。

于 2017-12-14T21:58:33.940 回答
3

如果您在此之前看到 OutOfMemoryError,请尝试此操作

-XX:MaxDirectMemorySize=512M

请参阅https://issues.apache.org/jira/browse/HTTPASYNC-104

于 2019-05-28T17:15:36.387 回答
3

就我而言,使用 Elasticsearch 高级客户端,此异常是由于esclient.indexAsync(indexRequest,RequestOptions.DEFAULT,null)

我通过在这样的所有异步请求中添加一个动作侦听器来修复它

esclient.indexAsync(indexRequest,RequestOptions.DEFAULT, 
              new ActionListener<IndexResponse>() {

                    @Override

                    public void onResponse(IndexResponse response) {

                    }
                    @Override
                    public void onFailure(Exception e) {

                });
于 2020-05-31T12:38:50.573 回答
1

我们遇到了同样的问题,经过大量挖掘,我们发现IOReactorExceptionHandler需要向 HttpAsyncClient 提供适当的信息以避免这种情况。不幸的是,文档中没有很好地涵盖它。

下面是我们的代码片段,其中更强大的客户端构建器尝试添加异常处理程序。请注意,IOExceptions 仍然会停止 I/O 反应器,因为它们可能意味着底层网络通信失败。您可以根据自己的独特用例进行调整。

 public RobustCloseableHttpAsyncClientBuilder withDefaultExceptionHandler() {
    return withExceptionHandler(
        new IOReactorExceptionHandler() {

          @Override
          public boolean handle(RuntimeException ex) {
            logger.error(
                "RuntimeException occurs in callback, handled by default exception handler and the I/O reactor will be resumed.",
                ex);
            return true;
          }

          @Override
          public boolean handle(IOException ex) {
            logger.error(
                "IOException occurs in callback, handled by default exception handler and the I/O reactor will be stopped.",
                ex);
            return false;
          }
        });
  }

在 Github 上的 elasticsearch 中阅读此问题报告以获取更多信息。

于 2021-05-26T20:24:32.737 回答