Repository navigation
Closed
Labels
Description
Java API client version
7.17.28
Java version
java version "21.0.3" 2024-04-16 LTS
Elasticsearch Version
7.17.28
Problem description
Hello,
We are seeing frequent (about once per day) errors where the Apache HTTP client used by the Elasticsearch client stops working due to an I/O reactor terminated abnormally error.
Here is a full stack trace:
I/O dispatch worker terminated abnormally
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:359)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by java.util.NoSuchElementException: null
at java.base/java.util.Collections$1.next(Collections.java:5037)
at co.elastic.clients.transport.rest_client.MultiBufferEntity.init(MultiBufferEntity.java:65)
at co.elastic.clients.transport.rest_client.MultiBufferEntity.close(MultiBufferEntity.java:59)
at org.apache.http.nio.protocol.BasicAsyncRequestProducer.close(BasicAsyncRequestProducer.java:155)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.releaseResources(DefaultClientExchangeHandlerImpl.java:84)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.failed(AbstractClientExchangeHandler.java:429)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.exception(HttpAsyncRequestExecutor.java:163)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:276)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
[8 more]
Impact:
- When this happens, the HTTP client is marked as STOPPED.
- As a result, all subsequent calls to the Elasticsearch client fail with:
java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED
Additional Context:
- Apache HTTP versions:
org.apache.httpcomponents:httpasyncclient:4.1.4
org.apache.httpcomponents:httpclient:4.5.14
org.apache.httpcomponents:httpcore-nio:4.4.12
org.apache.httpcomponents:httpcore:4.4.16
- We use
BulkIngesterquite heavily. - As a temporary workaround, we have a watchdog thread that checks if the HTTP client is still running and recreates the RestClient if needed. (Pseudocode below:)
if (!httpClient.isRunning()) {
RestClient newClient = createClient();
// Atomically swap httpClient, using an AtomicReference
}Thanks for your help!
Activity
l-trotta commentedon May 5, 2025
Hello! From checking the code and the stacktrace you provided, I suspect that something "common" such as a TimeoutException is causing an exception in the RestClient code: from the stacktrace we can see the
HttpAsyncRequestExecutorfailing, then theDefaultClientExchangeHandlerImpltrying to release the resources of the producer, and finally some concurrency issue we didn't account for inMultiBufferEntityis triggering the NoSuchElementException.I'd like to first identify the initial exception, so that then we can reproduce the issue and analyze what's happening with MultiBufferEntity. Is there any other log you could provide? Setting the log level of the application to see more details could help.
Also:
LouisTrezzini commentedon May 7, 2025
Hi!
Thanks for the prompt answer. I will try to collect more logs. In the meantime, here are the answers to your questions:
Yes, our servers are directly connected to ES nodes
for
ElasticsearchClient:for
BulkIngester:it's hard to give a detailed explanation
the bulk ingester lives in a singleton bean in a tomcat/spring web application, so it's naturally multi threaded and
ingester.addcan be called from multiple threads concurrentlyhowever, I don't think the ingester is under pressure when the issue happens ("I/O reactor terminated abnormally" at 00:24:05.730)
(
pending_requests = ingester.pendingRequests() & pending_operations = ingester.pendingOperations())thanks again for your help!
LouisTrezzini commentedon May 12, 2025
Hi @l-trotta!
I added more logs, and they seem to point out to this exception (most likely) being raised right before the I/O reactor gets shut down:
or perhaps this
l-trotta commentedon May 12, 2025
Hey @LouisTrezzini, thanks for all the details! So, as suspected the underlying exceptions are networking related, and they are most likely caused by connectivity issues between the client and the Elasticsearch server. This is not something that can be fixed client side, and will probably need to be investigated. That said, the client definitely has a concurrency bug that is triggered by these specific exception, and I've been trying to replicate it with no success. I'll investigate more and update as soon as I have more information!
l-trotta commentedon May 27, 2025
Hey @LouisTrezzini! No luck on reproducing the issue, but since it's pretty clear where the problem is on the client side (the
NoSuchElementException) we'll try pushing a fix that hopefully should prevent it from happening. It's in version 7.17.29 of the client, which should be already available, so I'd be great if you could let me know if it solves the problem :)LouisTrezzini commentedon May 27, 2025
Thank you so much!
We are ready to test the new version, unfortunately I don't see it on maven yet: https://mvnrepository.com/artifact/co.elastic.clients/elasticsearch-java?sort=date
l-trotta commentedon May 28, 2025
Maven takes ~48h from the release to synchronize between instances and show new releases on the webpage, but it's already available to import :)
LouisTrezzini commentedon Jun 9, 2025
We haven't seen a single instance of
I/O dispatch worker terminated abnormallysince we upgraded the library on May 28, so I think your change fixed the issue.Thanks again!
l-trotta commentedon Jun 10, 2025
@LouisTrezzini thank you for your patience and the detailed reports :D
phil-haigh-m-and-s commentedon Jun 12, 2025
Apologies @l-trotta but is this fix applicable to later versions (like 8.18), and is there an issue or PR for the changes that were made that we can look at?
Ah ignore this, just seen the link to the PR above 🤦
l-trotta commentedon Jun 12, 2025
@phil-haigh-m-and-s we have not received any reports of this happening in versions other than 7.17, but since it something that could happen this will be applied to every future release and patch, so currently 8.17, 8.18 and 9.0, I just wanted to make sure that it worked first :)