1. 程式人生 > 其它 >【ElasticSearch】異常 Request cannot be executed; I/O reactor status: STOPPED

【ElasticSearch】異常 Request cannot be executed; I/O reactor status: STOPPED

Caused by: java.lang.RuntimeException: Request cannot be executed; I/O reactor status: STOPPED
    at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:857)
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:259)
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:
246) at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1613) at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1583) at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:
1553) at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:1069) at com.deyatech.esutil.service.impl.ElasticSearchServiceImpl.selectDataByESQueryJSON(ElasticSearchServiceImpl.java:581) at com.deyatech.esutil.service.impl.ElasticSearchServiceImpl.searchData(ElasticSearchServiceImpl.java:
548) at com.deyatech.reception.service.impl.InfoTemplateEsServiceImpl.getElaticsearchResult(InfoTemplateEsServiceImpl.java:251) at com.deyatech.reception.service.impl.InfoTemplateEsServiceImpl.getTemplateListView(InfoTemplateEsServiceImpl.java:120) at com.deyatech.reception.service.impl.InfoTemplateServiceImpl.getTemplateListView(InfoTemplateServiceImpl.java:221) at com.deyatech.reception.service.impl.InfoTemplateServiceImpl$$FastClassBySpringCGLIB$$aadf779.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) at org.springframework.cache.interceptor.CacheInterceptor.lambda$invoke$0(CacheInterceptor.java:53) at org.springframework.cache.interceptor.CacheAspectSupport.invokeOperation(CacheAspectSupport.java:366) at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:421) at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:346) at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691) at com.deyatech.reception.service.impl.InfoTemplateServiceImpl$$EnhancerBySpringCGLIB$$6d755bd7.getTemplateListView(<generated>) at com.deyatech.reception.thymeleaf.InfoDataExpressionObject.getInfoList(InfoDataExpressionObject.java:47) at sun.reflect.GeneratedMethodAccessor1001.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:902) at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1547) ... 113 common frames omitted Caused by: java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED at org.apache.http.util.Asserts.check(Asserts.java:46) at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase.ensureRunning(CloseableHttpAsyncClientBase.java:90) at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:123) at org.elasticsearch.client.RestClient.performRequest(RestClient.java:255) ... 143 common frames omitted

github已提的問題

https://github.com/elastic/elasticsearch/issues/42133

https://github.com/elastic/elasticsearch/issues/45115

https://github.com/elastic/elasticsearch/issues/49124

https://github.com/elastic/elasticsearch/issues/39946

一些可以嘗試的方法來解決問題

1、After some debugging and configuration tuning, I found that the exception was caused by too many concurrent ElasticSearch clients. After I reduce the number of concurrent clients, the exception is gone.
減少客戶端的數量,使用的地方都注入。

2、 I'm using the client at scheduled method, so every invocation is started in new thread. The client has been injected to the service and never closed. Seems that is the reason of exception in my case. I changed my implementation so a new client is created at every thread when it is needed and closes in the end of method. That fixed the issue.
每次使用都新建立客戶端,用完後關閉。

3、自己構建 RestHighLevelClient 使用 HttpComponents,連結STOP時重新構造客戶端