我有一个服务,预计将以每分钟~5个或更多请求的速度执行请求。此服务依赖于Apache AsyncHttpClient。每隔几分钟,客户端就会遇到一些条件,导致java.lang.IllegalStateException:请求无法执行;I/O反应器状态:已停止。对客户端的所有请求都开始失败,并显示相同的异常消息。服务重启后,此循环重复。
这个问题真的很难调试,因为请求执行失败并不会导致回调AsyncResponse的failed()方法。
据我所知,HttpCore NIO中有一个修复HTTPCORE-370,它在4.3.2中解决了类似的问题。我正在使用以下版本-
commons-httpclient-3.1.jar
httpasyncclient-4.1.1.jar
httpcore-4.4.4.jar
httpcore-nio-4.4.4.jar
然而,看到这个问题。
发布于 2019-05-29 01:15:36
如果您在此之前看到了OutOfMemoryError,请尝试以下内容
-XX:MaxDirectMemorySize=512M
发布于 2020-05-31 20:38:51
在我的例子中,使用了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) {
});发布于 2021-05-27 04:24:33
我们遇到了同样的问题,经过大量的挖掘,我们发现需要向HttpAsyncClient提供一个合适的IOReactorExceptionHandler来避免这种情况。不幸的是,文档中没有很好地涵盖这一点。
下面是我们的代码片段,其中更健壮的客户端构建器尝试添加异常处理程序。请注意,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中阅读此issue report以了解更多信息。
https://stackoverflow.com/questions/35350376
复制相似问题