一、问题描述
线上ES查询服务出现奇怪的问题,调用es查询数据的接口进行过一次查询,过几分钟之后再次用这个接口进行查询就不行了。
二、报错排查
简短报错:java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED
2023-09-28 06:58:29.166 ERROR 5612 --- [nio-8888-exec-2] c.c.e.service.impl.MailServiceImpl : java.lang.RuntimeException: Request cannot be executed; I/O reactor status: STOPPED
2023-09-28 06:58:29.168 ERROR 5612 --- [nio-8888-exec-2] o.a.c.c.C.[.[.[/es].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [/es] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: java.lang.RuntimeException: Request cannot be executed; I/O reactor status: STOPPED] with root cause
java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED
at org.apache.http.util.Asserts.check(Asserts.java:46) ~[httpcore-4.4.14.jar!/:4.4.14]
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase.ensureRunning(CloseableHttpAsyncClientBase.java:90) ~[httpasyncclient-4.1.4.jar!/:4.1.4]
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:123) ~[httpasyncclient-4.1.4.jar!/:4.1.4]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:279) ~[elasticsearch-rest-client-7.13.2.jar!/:7.13.2]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:270) ~[elasticsearch-rest-client-7.13.2.jar!/:7.13.2]
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1654) ~[elasticsearch-rest-high-level-client-7.13.2.jar!/:7.13.2]
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1624) ~[elasticsearch-rest-high-level-client-7.13.2.jar!/:7.13.2]
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1594) ~[elasticsearch-rest-high-level-client-7.13.2.jar!/:7.13.2]
at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:1110) ~[elasticsearch-rest-high-level-client-7.13.2.jar!/:7.13.2]
at com.cma.elasticsearch.service.impl.MailServiceImpl.findByMbidAndKeyword(MailServiceImpl.java:72) ~[classes!/:1.0.4-RELEASE]
at com.cma.elasticsearch.controller.MailController.findByMbidAndKeywordV1(MailController.java:94) ~[classes!/:1.0.4-RELEASE]
at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_332]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_332]
三、解决问题
经过排查发现可能是出现异常RestHighLevelClient提前关闭,导致后续接口调用出现问题。
1.下面的代码如果到抛出异常的情况会导致RestHighLevelClient停止和关闭
2.如果仍然有问题,可能就是httpclient版本低的问题,建议是pom修改升级版本
我这里是ES 7.13.3,升级后的httpclient是4.4.14。可以参考下面的依赖
</dependency>
<!-- httpclient、httpcore、 httpcore-nio这三个依赖 -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-nio</artifactId>
<version>4.4.14</version>
</dependency>
<!-- httpclient、httpcore、 httpcore-nio这三个依赖 -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.14</version>
</dependency>
文章来源地址https://www.toymoban.com/news/detail-830632.html文章来源:https://www.toymoban.com/news/detail-830632.html
到了这里,关于Java 调用Elasticsearch报错java.lang.IllegalStateException: Request cannot be executed; I/O reactor statu的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!