我正在使用httpcore-nio-4.4.5.jar。我正在使用elasticsearch RestHighLevelClient与我们的Elasticsearch服务器进行交互。所有这一切都正常,除了有时我们突然使I / O Reactor停止错误。
在ES方面,一切似乎都很好。没有奇怪的行为。
这就是我初始化ES客户端的方式。
public synchronized RestHighLevelClient getHighLevelClient() throws ManagerException {
if (highLevelClient != null) {
return highLevelClient;
}
Map<String, Integer> map = getEsServers(esAddresses);
HttpHost[] hosts = new HttpHost[map.size()];
int i = 0;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
hosts[i++] = new HttpHost(entry.getKey(), entry.getValue(), "http");
LOGGER.info(entry.getKey() + " " + entry.getValue());
}
RestClientBuilder restClientBuilder = RestClient.builder(hosts);
highLevelClient = customizeHttpClient(restClientBuilder);
return highLevelClient;
}
public RestHighLevelClient customizeHttpClient(RestClientBuilder restClientBuilder) {
Header[] defaultHeaders = new Header[2];
defaultHeaders[0] = new BasicHeader("Authorization", "Basic YTph");
defaultHeaders[1] = new BasicHeader("Accept", "application/json");
restClientBuilder.setDefaultHeaders(defaultHeaders);
restClientBuilder.setMaxRetryTimeoutMillis(MAX_RETRY_TIMEOUT_MILLIS);
restClientBuilder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder
.setConnectTimeout(CONNECT_TIMEOUT_MILLIS)
.setSocketTimeout(SOCKET_TIMEOUT_MILLIS)
.setConnectionRequestTimeout(CONNECTION_REQUEST_TIMEOUT_MILLIS));
restClientBuilder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder
.setMaxConnPerRoute(MAX_CONN_PER_ROUTE)
.setMaxConnTotal(MAX_CONN_TOTAL));
return new RestHighLevelClient(restClientBuilder);
}
所以基本上首先我得到以下堆栈跟踪
java.lang.IllegalStateException: I/O reactor has been shut down
at org.apache.http.util.Asserts.check(Asserts.java:34)
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.connect(DefaultConnectingIOReactor.java:224)
at org.apache.http.nio.pool.AbstractNIOConnPool.processPendingRequest(AbstractNIOConnPool.java:434)
at org.apache.http.nio.pool.AbstractNIOConnPool.lease(AbstractNIOConnPool.java:276)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:266)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.requestConnection(AbstractClientExchangeHandler.java:363)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:125)
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141)
at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:346)
at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:328)
at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:271)
at org.elasticsearch.client.RestHighLevelClient.performRequestAsync(RestHighLevelClient.java:537)
at org.elasticsearch.client.RestHighLevelClient.performRequestAsyncAndParseEntity(RestHighLevelClient.java:515)
at org.elasticsearch.client.RestHighLevelClient.searchAsync(RestHighLevelClient.java:400)
,在那之后没有超时只是连续出现以下异常,直到我重新启动服务器。
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.performRequestAsync(RestClient.java:346)
at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:328)
at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:271)
at org.elasticsearch.client.RestHighLevelClient.performRequestAsync(RestHighLevelClient.java:537)
at org.elasticsearch.client.RestHighLevelClient.performRequestAsyncAndParseEntity(RestHighLevelClient.java:515)
at org.elasticsearch.client.RestHighLevelClient.searchAsync(RestHighLevelClient.java:400) ```
答案 0 :(得分:0)
我遇到了同样的问题,事实证明我没有关闭HighLevelRestClient。
请参阅https://discuss.elastic.co/t/request-cannot-be-executed-i-o-reactor-status-stopped/195438/4上的HenningAndersen答案:
这听起来类似于https://github.com/elastic/elasticsearch/issues/45115141。该问题中的问题是由客户端应用程序代码中的onFailure方法中引发异常引起的。这将导致连接被关闭,后续请求将失败,并显示此处报告的错误。
我认为,如果使用通过ActionListener返回响应/故障的任何方法(我认为所有方法名称的后缀均为Async),这也会影响高级客户端。
解决方法是确保确保您的 onFailure 方法中没有没有例外。