[英]Getting this error out of a sudden java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED
I'm using httpcore-nio-4.4.5.jar.我正在使用 httpcore-nio-4.4.5.jar。 I'm using the elasticsearch RestHighLevelClient to interact with our elasticsearch servers.
我正在使用 elasticsearch RestHighLevelClient 与我们的 elasticsearch 服务器进行交互。 This all works fine except for some time we get I/O reactor stopped error out of a sudden.
这一切都很好,除了有一段时间我们突然出现 I/O 反应器停止错误。
Everything seems fine on ES side.在 ES 方面一切似乎都很好。 No strange behaviour.
没有奇怪的行为。
That's how i'm initializing my ES client.这就是我初始化我的 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);
}
So basically first I get the following stacktrace所以基本上首先我得到以下堆栈跟踪
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)
and after that no Timeout just the following exception continuously until i restart my servers.在那之后没有超时,只是不断出现以下异常,直到我重新启动我的服务器。
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) ```
I was facing the same issue, and it turned out I was not closing the HighLevelRestClient.我遇到了同样的问题,结果我没有关闭 HighLevelRestClient。
Refer to HenningAndersen answer at https://discuss.elastic.co/t/request-cannot-be-executed-io-reactor-status-stopped/195438/4 :请参阅https://discuss.elastic.co/t/request-cannot-be-executed-io-reactor-status-stopped/195438/4上的 HenningAndersen 回答:
This sounds similar to https://github.com/elastic/elasticsearch/issues/45115 141. The problem in that issue is caused by throwing an exception in an onFailure method in the client application code.
这听起来类似于https://github.com/elastic/elasticsearch/issues/45115 141。该问题中的问题是由于在客户端应用程序代码中的 onFailure 方法中抛出异常引起的。 This causes the connection to be closed and subsequent requests will fail with the error reported here.
这会导致连接关闭,后续请求将失败并报告此处的错误。
I believe this also affects the high level client if using any of the methods reporting response/failure back through an ActionListener (I think all of them have suffix Async in their method names).
我相信,如果使用任何通过 ActionListener 报告响应/失败的方法(我认为它们的方法名称中都有后缀 Async),这也会影响高级客户端。
The workaround is to ensure that no exceptions are thrown out of your onFailure methods.
解决方法是确保您的onFailure方法不会抛出任何异常。
Change the condition of getHighLevelClient()
to if (highLevelClient.= null && highLevelClient.getLowLevelClient().isRunning())
将
getHighLevelClient()
的条件改为if (highLevelClient.= null && highLevelClient.getLowLevelClient().isRunning())
which means if the low level client (RestClient) is not running, you should renew the client, that works for me.这意味着如果低级客户端(RestClient)没有运行,你应该更新客户端,这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.