Skip to content

Permanently unusable client using httpclient5-based transport (I/O reactor has been shut down) #1046

Closed

Description

@marcreichman-pfi

Java API client version

9.0.4

Java version

21

Elasticsearch Version

9.0.4

Problem description

Hello,

We are trying to diagnose an issue which seems to have only started to come up with the new transport. This looks similar to #1003, but it's with the httpclient5 transport.

We have an application which makes various periodic queries, some more involved than others, and phases of intense indexing work. This app has been using Elasticsearch since 2.x era, and has used every client along the way: TransportClient, HLRC, "new" Java client with elasticsearch-rest-client, and now the client with HTTPClient5 transport. The structure and query patterns of the app have not changed in any notable way over this period.

This past weekend, the app was deployed for the first time with the HTTPClient5 transport to two different machines, one with 10 nodes on a low-cpu-constrained client environment without TLS or users, and another with a cpu-constrained environment on a single node (same machine) with TLS and users. The nodes all run on the dockerized version of ES 9.0.4.

Both environments went through an index migration from our side, using the bulk ingester class, and then resumed the normal activities of occasional queries and occasional indexing requests.

The constrained environment has now twice this weekend gotten into a state where queries cannot be run, and there are log entries that I/O reactor has been shut down every time the client tries to operate, and nothing brings it back except restarts / reinitializations of the client code.

Some of our code is more funky regarding the CompleteableFuture patterns, but even simple code like this can bring it out once it's in this state:

final String finalIndexPattern = "myIndexv*";
final int INDEX_OPERATION_DEFAULT_TIMEOUT_SEC = 45;
List<IndicesRecord> r = client.cat().indices(t -> t.index(finalIndexPattern)).get(INDEX_OPERATION_DEFAULT_TIMEOUT_SEC, TimeUnit.SECONDS).indices();

An example of the trace:

org.apache.hc.core5.reactor.IOReactorShutdownException: I/O reactor has been shut down
...
Caused by: java.util.concurrent.ExecutionException: org.apache.hc.core5.reactor.IOReactorShutdownException: I/O reactor has been shut down
        at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
        at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096)
        at <snip - private code>
        ... 106 more
Caused by: org.apache.hc.core5.reactor.IOReactorShutdownException: I/O reactor has been shut down
        at org.apache.hc.core5.reactor.AbstractIOReactorBase.connect(AbstractIOReactorBase.java:50)
        at org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester$2.executeNext(MultihomeIOSessionRequester.java:139)
        at org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester$2.run(MultihomeIOSessionRequester.java:188)
        at org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester.connect(MultihomeIOSessionRequester.java:192)
        at org.apache.hc.client5.http.impl.nio.DefaultAsyncClientConnectionOperator.connect(DefaultAsyncClientConnectionOperator.java:115)
        at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager.connect(PoolingAsyncClientConnectionManager.java:453)
        at org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime.connectEndpoint(InternalHttpAsyncExecRuntime.java:226)
        at org.apache.hc.client5.http.impl.async.AsyncConnectExec.doProceedToNextHop(AsyncConnectExec.java:220)
        at org.apache.hc.client5.http.impl.async.AsyncConnectExec.proceedToNextHop(AsyncConnectExec.java:195)
        at org.apache.hc.client5.http.impl.async.AsyncConnectExec.access$000(AsyncConnectExec.java:90)
        at org.apache.hc.client5.http.impl.async.AsyncConnectExec$1.completed(AsyncConnectExec.java:162)
        at org.apache.hc.client5.http.impl.async.AsyncConnectExec$1.completed(AsyncConnectExec.java:151)
        at org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime$1.completed(InternalHttpAsyncExecRuntime.java:128)
        at org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime$1.completed(InternalHttpAsyncExecRuntime.java:120)
        at org.apache.hc.core5.concurrent.BasicFuture.completed(BasicFuture.java:148)
        at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$3$1.leaseCompleted(PoolingAsyncClientConnectionManager.java:336)
        at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$3$1.completed(PoolingAsyncClientConnectionManager.java:321)
        at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$3$1.completed(PoolingAsyncClientConnectionManager.java:282)
        at org.apache.hc.core5.concurrent.BasicFuture.completed(BasicFuture.java:148)
        at org.apache.hc.core5.pool.StrictConnPool.fireCallbacks(StrictConnPool.java:401)
        at org.apache.hc.core5.pool.StrictConnPool.lease(StrictConnPool.java:219)
        at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$3.<init>(PoolingAsyncClientConnectionManager.java:279)
        at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager.lease(PoolingAsyncClientConnectionManager.java:274)
        at org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime.acquireEndpoint(InternalHttpAsyncExecRuntime.java:115)
        at org.apache.hc.client5.http.impl.async.AsyncConnectExec.execute(AsyncConnectExec.java:150)
        at org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
        at org.apache.hc.client5.http.impl.async.AsyncProtocolExec.internalExecute(AsyncProtocolExec.java:207)
        at org.apache.hc.client5.http.impl.async.AsyncProtocolExec.execute(AsyncProtocolExec.java:172)
        at org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
        at org.apache.hc.client5.http.impl.async.AsyncHttpRequestRetryExec.internalExecute(AsyncHttpRequestRetryExec.java:113)
        at org.apache.hc.client5.http.impl.async.AsyncHttpRequestRetryExec.execute(AsyncHttpRequestRetryExec.java:211)
        at org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
        at org.apache.hc.client5.http.impl.async.AsyncRedirectExec.internalExecute(AsyncRedirectExec.java:111)
        at org.apache.hc.client5.http.impl.async.AsyncRedirectExec.execute(AsyncRedirectExec.java:278)
        at org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
        at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient.executeImmediate(InternalAbstractHttpAsyncClient.java:386)
        at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient.lambda$doExecute$0(InternalAbstractHttpAsyncClient.java:242)
        at org.apache.hc.core5.http.nio.support.BasicRequestProducer.sendRequest(BasicRequestProducer.java:93)
        at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient.doExecute(InternalAbstractHttpAsyncClient.java:209)
        at org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:96)
        at org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:106)
        at co.elastic.clients.transport.rest5_client.low_level.Rest5Client.lambda$performRequestAsync$1(Rest5Client.java:407)
        at co.elastic.clients.transport.rest5_client.low_level.Cancellable$RequestCancellable.runIfNotCancelled(Cancellable.java:98)
        at co.elastic.clients.transport.rest5_client.low_level.Rest5Client.performRequestAsync(Rest5Client.java:404)
        at co.elastic.clients.transport.rest5_client.low_level.Rest5Client.performRequestAsync(Rest5Client.java:391)
        at co.elastic.clients.transport.rest5_client.Rest5ClientHttpClient.performRequestAsync(Rest5ClientHttpClient.java:114)
        at co.elastic.clients.transport.ElasticsearchTransportBase.performRequestAsync(ElasticsearchTransportBase.java:190)
        at co.elastic.clients.elasticsearch.cat.ElasticsearchCatAsyncClient.indices(ElasticsearchCatAsyncClient.java:538)
        at co.elastic.clients.elasticsearch.cat.ElasticsearchCatAsyncClient.indices(ElasticsearchCatAsyncClient.java:576)
        ... 107 more

The original exception, before all requests show the reactor error, is that the connection is closed:

Caused by: java.util.concurrent.ExecutionException: org.apache.hc.core5.http.RequestNotExecutedException: Connection is closed
        at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
        at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096)
        at <snip - private code>
        ... 106 more
Caused by: org.apache.hc.core5.http.RequestNotExecutedException: Connection is closed
        at org.apache.hc.core5.http.nio.command.CommandSupport.cancelCommands(CommandSupport.java:68)
        at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onDisconnect(AbstractHttp1StreamDuplexer.java:415)
        at org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.disconnected(AbstractHttp1IOEventHandler.java:95)
        at org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.disconnected(ClientHttp1IOEventHandler.java:41)
        at org.apache.hc.core5.reactor.ssl.SSLIOSession$1.disconnected(SSLIOSession.java:253)
        at org.apache.hc.core5.reactor.InternalDataChannel.disconnected(InternalDataChannel.java:205)
        at org.apache.hc.core5.reactor.SingleCoreIOReactor.processClosedSessions(SingleCoreIOReactor.java:229)
        at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:131)
        at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:92)
        at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
        ... 1 more

I'm not surprised about the occasional close with the heavy environment, but like I've said, nothing has really changed except for the update to 9.x and the httpclient. We were on elasticsearch-java 8.18.0 with elasticsearch-rest-client 9.0.3 immediately before this deployment.

What other information would be preferable? I am running more tests with the CPU constraint relaxed a bit more, to see if this is bringing out the situation, as a data point to help distinguish the other different factors between systems (single node, same host, tls, user auth). My next plan after this is to switch back to the elasticsearch-rest-client 9.0.4 and revert the client initialization changes to see if it pops up again with this environment under load.

Thanks for your time!

Activity

  1. marcreichman-pfi commented on Aug 4, 2025

    @marcreichman-pfi
    Author

    It seems like this method should probably be called during client building.

    Information gleaned mostly from this thread.

    I am going to also experiment with .setHttpClientConfigCallback to try to use setIoReactorExceptionCallback(..). I believe the default code should set this, however.

  2. l-trotta commented on Aug 11, 2025

    @l-trotta
    Contributor

    Hello @marcreichman-pfi and thank you for the detailed report. I believe this is caused by the missing SafeResponseConsumer which was set by default in the old RestClient and would avoid reactor shutdowns in case of exceptions. When writing the updated Rest5Client I couldn't manage to trigger an IoReactor shutdown, so I naively assumed graceful shutdowns to be handled at the library level... seems I was wrong ^^" sorry for the mess. I'll add a SafeResponseConsumer implementation to Rest5Client in the next patch, I'll update you when it will be out!

  3. l-trotta commented on Aug 13, 2025

    @l-trotta
    Contributor

    @marcreichman-pfi will be out in 9.1.1 and 9.0.5, available now (might have to wait a bit to have them show in maven central though). please let me know if it fixes the issue :)

  4. marcreichman-pfi commented on Aug 13, 2025

    @marcreichman-pfi
    Author

    Thank you @l-trotta ! Appreciate your quick turnaround.

  5. marcreichman-pfi commented on Aug 22, 2025

    @marcreichman-pfi
    Author

    @l-trotta just FYI I have not seen this once in 9.0.5+

  6. marcreichman-pfi commented on Nov 19, 2025

    @marcreichman-pfi
    Author

    @l-trotta I'm not sure if this warrants a reopen but I did see this again today using 9.0.8, on a system which was very bogged down during an index version migration. Heavy use of bulk ingester, several queries going on as well. I have logs, what do you need?

  7. l-trotta commented on Nov 19, 2025

    @l-trotta
    Contributor

    hey @marcreichman-pfi, trace logs as the ones in the PR description should be enough!

  8. marcreichman-pfi commented on Nov 19, 2025

    @marcreichman-pfi
    Author

    Here's a larger version, we were coming in from many threads with bulk ingester, so I have lots to pick from.

    trace.log

    this is a sample of our client init code. Most notably that error log did not fire.

     Rest5ClientBuilder builder = Rest5Client
                    .builder(httpHosts.toArray(new HttpHost[0]))
                    .setConnectionConfigCallback(connectConf -> connectConf
                            .setConnectTimeout(Timeout.of(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS))
                            .setSocketTimeout(Timeout.of(getSocketTimeoutMS(), TimeUnit.MILLISECONDS)))
                    .setConnectionManagerCallback(connectMgr -> connectMgr
                            .setMaxConnTotal(MAX_CONN_TOTAL)
                            .setMaxConnPerRoute(MAX_CONN_PER_ROUTE))
                    .setHttpClientConfigCallback(cb -> cb
                            .setIoReactorExceptionCallback(ioReactorEx -> {
                                // maybe this will identify the reason the reactor is shut down
                                log.error("Uncaught IO Reactor exception from low level Elasticsearch client", ioReactorEx);
                            }));
  9. l-trotta commented on Nov 20, 2025

    @l-trotta
    Contributor

    unfortunately the logs only show what's happening after the IO reactor was shut down, we'd need to know the original reason to investigate... weird that it didn't trigger the callback if that's the case! if you could get logs with the start of the exceptions, maybe there could be something happening before. In the meantime I'll investigate if it's possible for the IO reactor to shut down without throwing exception.

  10. marcreichman-pfi commented on Nov 20, 2025

    @marcreichman-pfi
    Author

    Hi @l-trotta, that is actually the start of all exceptions. It's possible that the initial condition hit the logs out of order, though, since this is a bulk ingester situation with a feeding queue/thread pool to 8 concurrent requests. I do see a connection is closed exception at 2025-11-19 11:12:28,774 which is after the initial message (for Bulk operation 3499). I also see some info from a different query outside of the bulk helper at 2025-11-19 11:20:30,141 with a different connection is closed.

    So there are various connection is closed scattered around there, besides just the IO reactor being shut down. I am not sure how to trap any earlier state as there are no error messages associated. Is there a higher verbosity for ES client or HC5 I should use? I don't encounter this often, as you can see from the rate of my messages to this ticket.

  11. marcreichman-pfi commented on Nov 20, 2025

    @marcreichman-pfi
    Author

    aha - I did find this about 10-12m before the other exceptions started, from a different log:

    [2025-11-19T11:01:31.761-0600] [Payara 6.2025.7] [SEVERE] [] [] [tid: _ThreadID=484 _ThreadName=elasticsearch-rest-client-0-thread-5] [timeMillis: 1763571691761] [levelValue: 1000] [[
      Exception in thread "elasticsearch-rest-client-0-thread-5" ]]
    
    [2025-11-19T11:01:31.920-0600] [Payara 6.2025.7] [SEVERE] [] [] [tid: _ThreadID=484 _ThreadName=elasticsearch-rest-client-0-thread-5] [timeMillis: 1763571691920] [levelValue: 1000] [[
      java.lang.OutOfMemoryError: Java heap space
            at java.base/java.util.Arrays.copyOf(Arrays.java:3541)
            at java.base/java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:100)
            at java.base/java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:132)
            at java.base/java.nio.channels.Channels$WritableByteChannelImpl.write(Channels.java:392)
            at co.elastic.clients.transport.rest5_client.MultiBufferEntity.writeTo(MultiBufferEntity.java:94)
            at co.elastic.clients.transport.rest5_client.MultiBufferEntity.getContent(MultiBufferEntity.java:86)
            at co.elastic.clients.transport.rest5_client.low_level.BasicAsyncEntityProducer.produce(BasicAsyncEntityProducer.java:108)
            at org.apache.hc.core5.http.nio.support.BasicRequestProducer.produce(BasicRequestProducer.java:104)
            at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient$3.produce(InternalAbstractHttpAsyncClient.java:297)
            at org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.produce(HttpAsyncMainClientExec.java:167)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.commitRequest(ClientHttp1StreamHandler.java:183)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.lambda$produceOutput$0(ClientHttp1StreamHandler.java:199)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler$$Lambda/0x00007fef7d6ab340.sendRequest(Unknown Source)
            at org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.produceRequest(HttpAsyncMainClientExec.java:154)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.produceOutput(ClientHttp1StreamHandler.java:199)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer.execute(ClientHttp1StreamDuplexer.java:331)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.processCommands(AbstractHttp1StreamDuplexer.java:244)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onOutput(AbstractHttp1StreamDuplexer.java:391)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.outputReady(AbstractHttp1IOEventHandler.java:73)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.outputReady(ClientHttp1IOEventHandler.java:41)
            at org.apache.hc.core5.reactor.ssl.SSLIOSession.encryptData(SSLIOSession.java:657)
            at org.apache.hc.core5.reactor.ssl.SSLIOSession.access$400(SSLIOSession.java:74)
            at org.apache.hc.core5.reactor.ssl.SSLIOSession$1.outputReady(SSLIOSession.java:210)
            at org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:153)
            at org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51)
            at org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:176)
            at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:125)
            at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:92)
            at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
            at java.base/java.lang.Thread.runWith(Thread.java:1596)
            at java.base/java.lang.Thread.run(Thread.java:1583)
    ]]
    

    Maybe that sheds some light on why the handler didn't fire.

  12. l-trotta commented on Nov 20, 2025

    @l-trotta
    Contributor

    considering the customized use of Rest5Client I'm suspecting something: how is the actual ElasticsearchClient created? The default builders use the SafeResponseConsumer, which was the solution when the problem first appeared, but if the creation of the client + rest client is customized then it's possible that the SafeResponseConsumer is not set, so there's nothing preventing the OOME from shutting down the IO reactor.

  13. marcreichman-pfi commented on Nov 25, 2025

    @marcreichman-pfi
    Author

    @l-trotta So sorry for the delayed response.

    Here is the entire code (sanitized) of client creation:

     log.debug("Creating new Elasticsearch (" + descriptiveName + ") REST client for host(s): " + esHost);
    
            final List<HttpHost> httpHosts = new ArrayList<>();
            for (String host : esHost.split(",")) {
                if (!host.trim().isEmpty()) {
                    httpHosts.add(new HttpHost(esClientScheme, host.trim(), esClientPort));
                }
            }
    
            Rest5ClientBuilder builder = Rest5Client
                    .builder(httpHosts.toArray(new HttpHost[0]))
                    .setConnectionConfigCallback(connectConf -> connectConf
                            .setConnectTimeout(Timeout.of(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS))
                            .setSocketTimeout(Timeout.of(getSocketTimeoutMS(), TimeUnit.MILLISECONDS)))
                    .setConnectionManagerCallback(connectMgr -> connectMgr
                            .setMaxConnTotal(MAX_CONN_TOTAL)
                            .setMaxConnPerRoute(MAX_CONN_PER_ROUTE))
                    .setHttpClientConfigCallback(cb -> cb
                            .setIoReactorExceptionCallback(ioReactorEx -> {
                                // maybe this will identify the reason the reactor is shut down
                                log.error("Uncaught IO Reactor exception from low level Elasticsearch client", ioReactorEx);
                            }));
    
            if (!esUsername.isEmpty() && !esPassword.isEmpty()) {
                String auth = esUsername + ":" + esPassword;
                String basicAuthHeader = "Basic " + Base64.getEncoder().encodeToString(auth.getBytes(StandardCharsets.UTF_8));
                builder.setDefaultHeaders(new BasicHeader[]{
                        new BasicHeader("Authorization", basicAuthHeader)
                });
            }
    
            this.transport = new Rest5ClientTransport(builder.build(), new JacksonJsonpMapper());
            this.esJavaClient = new ElasticsearchAsyncClient(transport, new Rest5ClientOptions(
                    RequestOptions.DEFAULT.toBuilder()
                            .setHttpAsyncResponseConsumerFactory(() -> new SafeResponseConsumer<>(
                                    new HttpAsyncResponseConsumerFactory
                                            .BasicAsyncResponseConsumerFactory(MAX_RESPONSE_ENTITY_SIZE)
                                            .createHttpAsyncResponseConsumer()))
                            .build(),
                    false));

    I had made the adjustment to use the safe response consumer ourselves after some of the previous messages months ago (related to #1054). This code has not been changed since then. We use our own consumer factory override to tolerate larger responses than the default.

  14. 1 remaining item

  15. marcreichman-pfi commented on Dec 2, 2025

    @marcreichman-pfi
    Author

    @l-trotta Thanks, I will try to reproduce although it's uncommon. I don't get DEBUG levels from the apache http5 client. I'll see about digging into how to set this up. We use log4j-slf4j2-impl, so it may just be that i'd need to add a logger for org.apache.hc.client5 to a dedicated file. I'll see what I can do and if I can reproduce.

  16. marcreichman-pfi commented on Dec 2, 2025

    @marcreichman-pfi
    Author

    @l-trotta OK - it took a few tries but I made it happen. It definitely correlates with an OOM a bit before the shutdown time. So with that I can probably make it happen with a smaller heap in my app.

    Just to review the usage pattern, this is the client as written above, and a "full reindex" of data from our database, which is basically a queue-driven thread pool which feeds a bulk ingester. The bulk ingester setting is as follows:

    • max concurrent requests: 8
    • max operations: 5000
    • max size: 25mb
    • flush interval: 5 seconds

    Generally when this runs it tends to crush the nodes a bit, and slides a window from the bulk ingester concurrent reqs back to the thread pool (usually 32) and up the indexing queue (usually 10000) to block the calling producer for the queue. We use this all the time and have been since the days of ES 2.x and the transport client, through the HLRC, to the new client. We do this on many systems, this one seems to have a harder time with the memory load since it's a slower machine. I'm not sure if something in the http5/9.x entity code is more memory consuming than the previous approaches.

    Here is the original OOM - maybe the thread matters for later?:

    [2025-12-02T14:44:32.767-0600] [Payara 6.2025.7] [SEVERE] [] [] [tid: _ThreadID=509 _ThreadName=elasticsearch-rest-client-1-thread-2] [timeMillis: 1764708272767] [levelValue: 1000] [[
      Exception in thread "elasticsearch-rest-client-1-thread-2" ]]
    
    [2025-12-02T14:44:32.780-0600] [Payara 6.2025.7] [SEVERE] [] [] [tid: _ThreadID=509 _ThreadName=elasticsearch-rest-client-1-thread-2] [timeMillis: 1764708272780] [levelValue: 1000] [[
      java.lang.OutOfMemoryError: Java heap space
            at java.base/java.util.Arrays.copyOf(Arrays.java:3541)
            at java.base/java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:100)
            at java.base/java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:132)
            at java.base/java.nio.channels.Channels$WritableByteChannelImpl.write(Channels.java:392)
            at co.elastic.clients.transport.rest5_client.MultiBufferEntity.writeTo(MultiBufferEntity.java:94)
            at co.elastic.clients.transport.rest5_client.MultiBufferEntity.getContent(MultiBufferEntity.java:86)
            at co.elastic.clients.transport.rest5_client.low_level.BasicAsyncEntityProducer.produce(BasicAsyncEntityProducer.java:108)
            at org.apache.hc.core5.http.nio.support.BasicRequestProducer.produce(BasicRequestProducer.java:104)
            at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient$3.produce(InternalAbstractHttpAsyncClient.java:297)
            at org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.produce(HttpAsyncMainClientExec.java:167)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.commitRequest(ClientHttp1StreamHandler.java:183)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.lambda$produceOutput$0(ClientHttp1StreamHandler.java:199)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler$$Lambda/0x00007f91c56dc1c0.sendRequest(Unknown Source)
            at org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.produceRequest(HttpAsyncMainClientExec.java:154)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.produceOutput(ClientHttp1StreamHandler.java:199)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer.execute(ClientHttp1StreamDuplexer.java:331)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.processCommands(AbstractHttp1StreamDuplexer.java:244)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onOutput(AbstractHttp1StreamDuplexer.java:391)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.outputReady(AbstractHttp1IOEventHandler.java:73)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.outputReady(ClientHttp1IOEventHandler.java:41)
            at org.apache.hc.core5.reactor.ssl.SSLIOSession.encryptData(SSLIOSession.java:657)
            at org.apache.hc.core5.reactor.ssl.SSLIOSession.access$400(SSLIOSession.java:74)
            at org.apache.hc.core5.reactor.ssl.SSLIOSession$1.outputReady(SSLIOSession.java:210)
            at org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:153)
            at org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51)
            at org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:176)
            at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:125)
            at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:92)
            at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
            at java.base/java.lang.Thread.runWith(Thread.java:1596)
            at java.base/java.lang.Thread.run(Thread.java:1583)
    ]]

    Here are some of the fresh failures:

    2025-12-02 15:03:43,037 ERROR[bulk-ingester-executor#2#666](ElasticSearchBulkProcessListener.java:234) Bulk operation 8460: threw an exception
    org.apache.hc.core5.reactor.IOReactorShutdownException: I/O reactor has been shut down
            at org.apache.hc.core5.reactor.IOWorkers.validate(IOWorkers.java:51)
            at org.apache.hc.core5.reactor.IOWorkers.access$000(IOWorkers.java:31)
            at org.apache.hc.core5.reactor.IOWorkers$GenericSelector.next(IOWorkers.java:84)
            at org.apache.hc.core5.reactor.AbstractIOReactorBase.connect(AbstractIOReactorBase.java:53)
            at org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester$2.executeNext(MultihomeIOSessionRequester.java:139)
            at org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester$2.run(MultihomeIOSessionRequester.java:188)
            at org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester.connect(MultihomeIOSessionRequester.java:192)
            at org.apache.hc.client5.http.impl.nio.DefaultAsyncClientConnectionOperator.connect(DefaultAsyncClientConnectionOperator.java:115)
            at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager.connect(PoolingAsyncClientConnectionManager.java:453)
            at org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime.connectEndpoint(InternalHttpAsyncExecRuntime.java:226)
            at org.apache.hc.client5.http.impl.async.AsyncConnectExec.doProceedToNextHop(AsyncConnectExec.java:220)
            at org.apache.hc.client5.http.impl.async.AsyncConnectExec.proceedToNextHop(AsyncConnectExec.java:195)
            at org.apache.hc.client5.http.impl.async.AsyncConnectExec.access$000(AsyncConnectExec.java:90)
            at org.apache.hc.client5.http.impl.async.AsyncConnectExec$1.completed(AsyncConnectExec.java:162)
            at org.apache.hc.client5.http.impl.async.AsyncConnectExec$1.completed(AsyncConnectExec.java:151)
            at org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime$1.completed(InternalHttpAsyncExecRuntime.java:128)
            at org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime$1.completed(InternalHttpAsyncExecRuntime.java:120)
            at org.apache.hc.core5.concurrent.BasicFuture.completed(BasicFuture.java:148)
            at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$3$1.leaseCompleted(PoolingAsyncClientConnectionManager.java:336)
            at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$3$1.completed(PoolingAsyncClientConnectionManager.java:321)
            at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$3$1.completed(PoolingAsyncClientConnectionManager.java:282)
            at org.apache.hc.core5.concurrent.BasicFuture.completed(BasicFuture.java:148)
            at org.apache.hc.core5.pool.StrictConnPool.fireCallbacks(StrictConnPool.java:401)
            at org.apache.hc.core5.pool.StrictConnPool.lease(StrictConnPool.java:219)
            at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager$3.<init>(PoolingAsyncClientConnectionManager.java:279)
            at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager.lease(PoolingAsyncClientConnectionManager.java:274)
            at org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime.acquireEndpoint(InternalHttpAsyncExecRuntime.java:115)
            at org.apache.hc.client5.http.impl.async.AsyncConnectExec.execute(AsyncConnectExec.java:150)
            at org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
            at org.apache.hc.client5.http.impl.async.AsyncProtocolExec.internalExecute(AsyncProtocolExec.java:207)
            at org.apache.hc.client5.http.impl.async.AsyncProtocolExec.execute(AsyncProtocolExec.java:172)
            at org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
            at org.apache.hc.client5.http.impl.async.AsyncHttpRequestRetryExec.internalExecute(AsyncHttpRequestRetryExec.java:113)
            at org.apache.hc.client5.http.impl.async.AsyncHttpRequestRetryExec.execute(AsyncHttpRequestRetryExec.java:211)
            at org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
            at org.apache.hc.client5.http.impl.async.AsyncRedirectExec.internalExecute(AsyncRedirectExec.java:111)
            at org.apache.hc.client5.http.impl.async.AsyncRedirectExec.execute(AsyncRedirectExec.java:278)
            at org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54)
            at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient.executeImmediate(InternalAbstractHttpAsyncClient.java:386)
            at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient.lambda$doExecute$0(InternalAbstractHttpAsyncClient.java:242)
            at org.apache.hc.core5.http.nio.support.BasicRequestProducer.sendRequest(BasicRequestProducer.java:93)
            at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient.doExecute(InternalAbstractHttpAsyncClient.java:209)
            at org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:96)
            at org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:106)
            at co.elastic.clients.transport.rest5_client.low_level.Rest5Client.lambda$performRequestAsync$1(Rest5Client.java:407)
            at co.elastic.clients.transport.rest5_client.low_level.Cancellable$RequestCancellable.runIfNotCancelled(Cancellable.java:98)
            at co.elastic.clients.transport.rest5_client.low_level.Rest5Client.performRequestAsync(Rest5Client.java:404)
            at co.elastic.clients.transport.rest5_client.low_level.Rest5Client.performRequestAsync(Rest5Client.java:391)
            at co.elastic.clients.transport.rest5_client.Rest5ClientHttpClient.performRequestAsync(Rest5ClientHttpClient.java:114)
            at co.elastic.clients.transport.ElasticsearchTransportBase.performRequestAsync(ElasticsearchTransportBase.java:190)
            at co.elastic.clients.elasticsearch.ElasticsearchAsyncClient.bulk(ElasticsearchAsyncClient.java:551)
            at co.elastic.clients.elasticsearch._helpers.bulk.BulkIngester.lambda$flush$3(BulkIngester.java:337)
            at co.elastic.clients.elasticsearch._helpers.bulk.FnCondition.whenReadyIf(FnCondition.java:89)
            at co.elastic.clients.elasticsearch._helpers.bulk.BulkIngester.flush(BulkIngester.java:300)
            at co.elastic.clients.elasticsearch._helpers.bulk.BulkIngester.lambda$innerAdd$13(BulkIngester.java:527)
            at co.elastic.clients.elasticsearch._helpers.bulk.FnCondition.lambda$whenReady$0(FnCondition.java:47)
            at co.elastic.clients.elasticsearch._helpers.bulk.FnCondition.whenReadyIf(FnCondition.java:89)
            at co.elastic.clients.elasticsearch._helpers.bulk.FnCondition.whenReady(FnCondition.java:46)
            at co.elastic.clients.elasticsearch._helpers.bulk.BulkIngester.innerAdd(BulkIngester.java:522)
            at co.elastic.clients.elasticsearch._helpers.bulk.BulkIngester.add(BulkIngester.java:501)
            at co.elastic.clients.elasticsearch._helpers.bulk.BulkIngester.add(BulkIngester.java:543)
            at myapp.search.es.control.ElasticSearchServiceClientBase.index(ElasticSearchServiceClientBase.java:349)
            at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
            at java.base/java.lang.reflect.Method.invoke(Method.java:580)
            at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:589)
            at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:409)
            at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4835)
            at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:654)
            at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:834)
            at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:604)
            at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
            at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
            at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
            at java.base/java.lang.reflect.Method.invoke(Method.java:580)
            at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:888)
            at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:833)
            at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:604)
            at org.jboss.weld.module.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:87)
            at org.jboss.weld.module.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
            at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
            at java.base/java.lang.reflect.Method.invoke(Method.java:580)
            at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:888)
            at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:833)
            at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:375)
            at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4807)
            at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4795)
            at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
            at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:90)
            at jdk.proxy71/jdk.proxy71.$Proxy418.index(Unknown Source)
            at myapp.search.es.control.__EJB31_Generated__ESIndexManager__Intf____Bean__.index(Unknown Source)
            at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
            at java.base/java.lang.reflect.Method.invoke(Method.java:580)
            at org.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:412)
            at org.jboss.weld.module.ejb.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:133)
            at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:54)
            at org.jboss.weld.module.ejb.InjectionPointPropagatingEnterpriseTargetBeanInstance.invoke(InjectionPointPropagatingEnterpriseTargetBeanInstance.java:69)
            at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:109)
            at myapp.search.es.control.ESIndexManager$Proxy$_$$_Weld$EnterpriseProxy$.index(Unknown Source)
            at myapp.search.es.control.EMMd5ESIndexingRunnable.indexIntoES(EMMd5ESIndexingRunnable.java:101)
            at myapp.search.es.control.EMMd5ESIndexingRunnable.run(EMMd5ESIndexingRunnable.java:56)
            at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
            at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
            at java.base/java.lang.Thread.run(Thread.java:1583)
            at org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl$ManagedThread.run(ManagedThreadFactoryImpl.java:322)
    2025-12-02 15:03:44,536 ERROR[bulk-ingester-executor#2#660](ElasticSearchBulkProcessListener.java:234) Bulk operation 8461: threw an exception
    org.apache.hc.core5.http.RequestNotExecutedException: Connection is closed
            at org.apache.hc.core5.http.nio.command.CommandSupport.cancelCommands(CommandSupport.java:68)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onDisconnect(AbstractHttp1StreamDuplexer.java:415)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.disconnected(AbstractHttp1IOEventHandler.java:95)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.disconnected(ClientHttp1IOEventHandler.java:41)
            at org.apache.hc.core5.reactor.ssl.SSLIOSession$1.disconnected(SSLIOSession.java:253)
            at org.apache.hc.core5.reactor.InternalDataChannel.disconnected(InternalDataChannel.java:205)
            at org.apache.hc.core5.reactor.SingleCoreIOReactor.processClosedSessions(SingleCoreIOReactor.java:229)
            at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:131)
            at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:92)
            at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
            at java.base/java.lang.Thread.run(Thread.java:1583)
    2025-12-02 15:03:45,609 ERROR[bulk-ingester-executor#2#666](ElasticSearchBulkProcessListener.java:234) Bulk operation 8462: threw an exception
    org.apache.hc.core5.http.RequestNotExecutedException: Connection is closed
            at org.apache.hc.core5.http.nio.command.CommandSupport.cancelCommands(CommandSupport.java:68)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onDisconnect(AbstractHttp1StreamDuplexer.java:415)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.disconnected(AbstractHttp1IOEventHandler.java:95)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.disconnected(ClientHttp1IOEventHandler.java:41)
            at org.apache.hc.core5.reactor.ssl.SSLIOSession$1.disconnected(SSLIOSession.java:253)
            at org.apache.hc.core5.reactor.InternalDataChannel.disconnected(InternalDataChannel.java:205)
            at org.apache.hc.core5.reactor.SingleCoreIOReactor.processClosedSessions(SingleCoreIOReactor.java:229)
            at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:131)
            at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:92)
            at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
            at java.base/java.lang.Thread.run(Thread.java:1583)
    2025-12-02 15:03:46,197 ERROR[bulk-ingester-executor#2#603](ElasticSearchBulkProcessListener.java:234) Bulk operation 8463: threw an exception
    org.apache.hc.core5.http.RequestNotExecutedException: Connection is closed
            at org.apache.hc.core5.http.nio.command.CommandSupport.cancelCommands(CommandSupport.java:68)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onDisconnect(AbstractHttp1StreamDuplexer.java:415)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.disconnected(AbstractHttp1IOEventHandler.java:95)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.disconnected(ClientHttp1IOEventHandler.java:41)
            at org.apache.hc.core5.reactor.ssl.SSLIOSession$1.disconnected(SSLIOSession.java:253)
            at org.apache.hc.core5.reactor.InternalDataChannel.disconnected(InternalDataChannel.java:205)
            at org.apache.hc.core5.reactor.SingleCoreIOReactor.processClosedSessions(SingleCoreIOReactor.java:229)
            at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:131)
            at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:92)
            at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
            at java.base/java.lang.Thread.run(Thread.java:1583)

    Finally, I'm attaching the entire httpclient5 debug file as you requested. It comes from before the heap issue (~14:44), the next bulk index starting (~15:01), and the problems starting to show with the reactor (~15:03). There were previous bulk index operations before and usual timers for things like checking nodes are up, so the log is quite busy and I'm gzipping it. I can see IMMEDIATE about ~100-125ms before the reactor shutdown errors. I hope this helps to make sense of things! I did this with only some apache logs in DEBUG because otherwise it was a flood and slowed it down too much. I can make this happen again if you need me to try other options/settings/log levels

    es_apache.log.gz

  17. marcreichman-pfi commented on Dec 3, 2025

    @marcreichman-pfi
    Author

    I'm running another test using setIOSessionListener to see if I can provide more useful info, with a slightly smaller heap to maybe cause it to generate again. If so I'll give another set of logs with the additional io session events.

    A couple thoughts:

    • The trace for the OOM seems to include the entity produce side, not consumption side. The Error of OOM means that typical exception blocks may not catch it and it seems like it's getting all the way out to the IOReactor itself and the java Thread. I wonder if it's worth catching something earlier just so better handling can be applied. But I also don't see how anything relating to the safe consumer could be involved here since it's on the production side.
    • Is this block of code (this is from before the project relocation) thread safe? Does it need to be? If there is a high traffic scenario to this block from multiple threads, and they all do that null check, they're all going to call the entity.getContent() and set the atomicreference. I wonder if synchronization is needed here, or some other approach to ensure thread safety, again if it is needed. I don't understand the whole flow of this particular async path so this is speculation.
    • Would it make sense to have the thread factory also register an uncaught exception handler?
  18. marcreichman-pfi commented on Dec 3, 2025

    @marcreichman-pfi
    Author

    @l-trotta Here is my latest update - I'll stop after this so you have a chance to look into things.

    Here's the OOM on elasticsearch-rest-client-2-thread-8 (9:33:35). As far as I can tell this was the JVM echoing to stdout (as is captured by this log) and the thread died.

    [2025-12-03T09:33:35.231-0600] [Payara 6.2025.7] [SEVERE] [] [] [tid: _ThreadID=531 _ThreadName=elasticsearch-rest-client-2-thread-8] [timeMillis: 1764776015231] [levelValue: 1000] [[
      Exception in thread "elasticsearch-rest-client-2-thread-8" ]]
    
    [2025-12-03T09:33:35.319-0600] [Payara 6.2025.7] [SEVERE] [] [] [tid: _ThreadID=531 _ThreadName=elasticsearch-rest-client-2-thread-8] [timeMillis: 1764776015319] [levelValue: 1000] [[
      java.lang.OutOfMemoryError: Java heap space
            at java.base/java.util.Arrays.copyOf(Arrays.java:3541)
            at java.base/java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:100)
            at java.base/java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:132)
            at java.base/java.nio.channels.Channels$WritableByteChannelImpl.write(Channels.java:392)
            at co.elastic.clients.transport.rest5_client.MultiBufferEntity.writeTo(MultiBufferEntity.java:94)
            at co.elastic.clients.transport.rest5_client.MultiBufferEntity.getContent(MultiBufferEntity.java:86)
            at co.elastic.clients.transport.rest5_client.low_level.BasicAsyncEntityProducer.produce(BasicAsyncEntityProducer.java:108)
            at org.apache.hc.core5.http.nio.support.BasicRequestProducer.produce(BasicRequestProducer.java:104)
            at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient$3.produce(InternalAbstractHttpAsyncClient.java:297)
            at org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.produce(HttpAsyncMainClientExec.java:167)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.commitRequest(ClientHttp1StreamHandler.java:183)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.lambda$produceOutput$0(ClientHttp1StreamHandler.java:199)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler$$Lambda/0x00007f4cad6adac0.sendRequest(Unknown Source)
            at org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.produceRequest(HttpAsyncMainClientExec.java:154)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.produceOutput(ClientHttp1StreamHandler.java:199)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer.execute(ClientHttp1StreamDuplexer.java:331)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.processCommands(AbstractHttp1StreamDuplexer.java:244)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onOutput(AbstractHttp1StreamDuplexer.java:391)
            at org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.outputReady(AbstractHttp1IOEventHandler.java:73)
            at org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.outputReady(ClientHttp1IOEventHandler.java:41)
            at org.apache.hc.core5.reactor.ssl.SSLIOSession.encryptData(SSLIOSession.java:657)
            at org.apache.hc.core5.reactor.ssl.SSLIOSession.access$400(SSLIOSession.java:74)
            at org.apache.hc.core5.reactor.ssl.SSLIOSession$1.outputReady(SSLIOSession.java:210)
            at org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:153)
            at org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51)
            at org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:176)
            at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:125)
            at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:92)
            at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
            at java.base/java.lang.Thread.runWith(Thread.java:1596)
            at java.base/java.lang.Thread.run(Thread.java:1583)
    ]]

    About 30 seconds before, these started using my new IO session listener logs and the logs I had before. They end for this thread elasticsearch-rest-client-2-thread-8 and for this... channel? c-0000000023 right when the OOM happens.

    2025-12-03 09:33:05,841 DEBUG[concurrent/__defaultManagedThreadFactory-Thread-16](PoolingAsyncClientConnectionManager.java:272) ex-0000001475 endpoint lease request (30000 MILLISECONDS) [route: {s}->[https://boston-cannons-int.pixelforensics.com:9200]][total available: 2; route allocated: 6
     of 30; total allocated: 6 of 30]
    2025-12-03 09:33:05,842 DEBUG[concurrent/__defaultManagedThreadFactory-Thread-16](PoolingAsyncClientConnectionManager.java:330) ex-0000001475 endpoint leased [route: {s}->[https://my-ssl-es-host:9200]][total available: 1; route allocated: 6 of 30; total allocated: 6 o
    f 30]
    2025-12-03 09:33:05,842 DEBUG[concurrent/__defaultManagedThreadFactory-Thread-16](PoolingAsyncClientConnectionManager.java:334) ex-0000001475 acquired ep-0000001475
    2025-12-03 09:33:05,842 DEBUG[concurrent/__defaultManagedThreadFactory-Thread-16](PoolingAsyncClientConnectionManager.java:756) ep-0000001475 executing exchange ex-0000001475 over c-0000000023
    2025-12-03 09:33:05,842 DEBUG[concurrent/__defaultManagedThreadFactory-Thread-16](DefaultManagedAsyncClientConnection.java:203) c-0000000023 RequestExecutionCommand with NORMAL priority
    2025-12-03 09:33:05,843 TRACE[elasticsearch-rest-client-2-thread-8](ElasticSearchIOSessionListener.java:37) ElasticSearchIOSession outputReady: c-0000000023[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][0]
    2025-12-03 09:33:05,891 TRACE[elasticsearch-rest-client-2-thread-8](ElasticSearchIOSessionListener.java:37) ElasticSearchIOSession outputReady: c-0000000023[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][0]
    2025-12-03 09:33:05,891 TRACE[elasticsearch-rest-client-2-thread-8](ElasticSearchIOSessionListener.java:37) ElasticSearchIOSession outputReady: c-0000000023[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][0]
    2025-12-03 09:33:05,891 TRACE[elasticsearch-rest-client-2-thread-8](ElasticSearchIOSessionListener.java:37) ElasticSearchIOSession outputReady: c-0000000023[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][0]
    2025-12-03 09:33:05,891 TRACE[elasticsearch-rest-client-2-thread-8](ElasticSearchIOSessionListener.java:37) ElasticSearchIOSession outputReady: c-0000000023[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][0]
    2025-12-03 09:33:05,892 TRACE[elasticsearch-rest-client-2-thread-8](ElasticSearchIOSessionListener.java:37) ElasticSearchIOSession outputReady: c-0000000023[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][0]
    2025-12-03 09:33:05,892 TRACE[elasticsearch-rest-client-2-thread-8](ElasticSearchIOSessionListener.java:37) ElasticSearchIOSession outputReady: c-0000000023[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][0]
    
    ... various other messages on this thread (lots of other threads in parallel not included):
    
    2025-12-03 09:33:08,338 TRACE[elasticsearch-rest-client-2-thread-8](ElasticSearchIOSessionListener.java:30) ElasticSearchIOSession inputReady: c-0000000023[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0]
    ...
    2025-12-03 09:33:08,339 DEBUG[elasticsearch-rest-client-2-thread-8](PoolingAsyncClientConnectionManager.java:395) ep-0000001475 releasing endpoint
    ...
    2025-12-03 09:33:08,339 DEBUG[elasticsearch-rest-client-2-thread-8](PoolingAsyncClientConnectionManager.java:414) ep-0000001475 connection c-0000000023 can be kept alive for 3 MINUTES
    ...
    2025-12-03 09:33:08,339 DEBUG[elasticsearch-rest-client-2-thread-8](PoolingAsyncClientConnectionManager.java:423) ep-0000001475 connection released [route: {s}->[https://my-ssl-es-host:9200]][total available: 2; route allocated: 6 of 30; total allocated: 6 of 30]
    ...
    
    ... then another cycle of the above few, and then..
    
    2025-12-03 09:33:35,064 DEBUG[concurrent/__defaultManagedThreadFactory-Thread-9](PoolingAsyncClientConnectionManager.java:272) ex-0000001507 endpoint lease request (30000 MILLISECONDS) [route: {s}->[https://my-ssl-es-host:9200]][total available: 3; route allocated: 6
    of 30; total allocated: 6 of 30]
    2025-12-03 09:33:35,065 DEBUG[concurrent/__defaultManagedThreadFactory-Thread-9](PoolingAsyncClientConnectionManager.java:330) ex-0000001507 endpoint leased [route: {s}->[https://my-ssl-es-host:9200]][total available: 2; route allocated: 6 of 30; total allocated: 6 of
     30]
    2025-12-03 09:33:35,065 DEBUG[concurrent/__defaultManagedThreadFactory-Thread-9](PoolingAsyncClientConnectionManager.java:334) ex-0000001507 acquired ep-0000001507
    2025-12-03 09:33:35,065 DEBUG[concurrent/__defaultManagedThreadFactory-Thread-9](PoolingAsyncClientConnectionManager.java:756) ep-0000001507 executing exchange ex-0000001507 over c-0000000023
    2025-12-03 09:33:35,065 DEBUG[concurrent/__defaultManagedThreadFactory-Thread-9](DefaultManagedAsyncClientConnection.java:203) c-0000000023 RequestExecutionCommand with NORMAL priority
    2025-12-03 09:33:35,072 TRACE[elasticsearch-rest-client-2-thread-8](ElasticSearchIOSessionListener.java:37) ElasticSearchIOSession outputReady: c-0000000023[ACTIVE][rw:w][ACTIVE][rw][NOT_HANDSHAKING][0][0][0]
    
    

    This was 159ms before the OOM, and is the last mention of any kind of thread elasticsearch-rest-client-2-thread-8 or c-0000000023.

    In this particular case, it took a bit longer from the OOM to the reactor shutdown.

    The reactor shutdown traces are the same as above, so I'll leave them out, but they start in the same way, from a regular query, and then immediately followed by the same ones on bulk operations from our listener. In this case though, the first IO reactor failure was 10:29:15,445 which is much longer than the usual 10 minutes or so. I suspect the extra debug logging added enough i/o overhead to stretch this out a bit.

    Just before the reactor failure messages started coming in, there was this. This came from the same thread as the original I/O reactor shut down message (__ejb-thread-pool10).

    2025-12-03 10:29:15,327 DEBUG[__ejb-thread-pool10](PoolingAsyncClientConnectionManager.java:720) ep-0000004328 close IMMEDIATE
    2025-12-03 10:29:15,333 DEBUG[__ejb-thread-pool10](PoolingAsyncClientConnectionManager.java:395) ep-0000004328 releasing endpoint
    2025-12-03 10:29:15,333 DEBUG[__ejb-thread-pool10](PoolingAsyncClientConnectionManager.java:423) ep-0000004328 connection released [route: {s}->[https://my-ssl-es-host:9200]][total available: 1; route allocated: 9 of 30; total allocated: 9 of 30]

    Within 200-225ms or so of this, we start getting other closes, and a shutdown:

    2025-12-03 10:29:15,556 DEBUG[elasticsearch-rest-client-2-thread-2](PoolingAsyncClientConnectionManager.java:720) ep-0000004330 close IMMEDIATE
    2025-12-03 10:29:15,556 DEBUG[elasticsearch-rest-client-2-thread-2](DefaultManagedAsyncClientConnection.java:83) c-0000000065 Shutdown connection IMMEDIATE
    2025-12-03 10:29:15,557 DEBUG[elasticsearch-rest-client-2-thread-2](PoolingAsyncClientConnectionManager.java:395) ep-0000004330 releasing endpoint
    2025-12-03 10:29:15,557 DEBUG[elasticsearch-rest-client-2-thread-2](PoolingAsyncClientConnectionManager.java:423) ep-0000004330 connection released [route: {s}->[https://my-ssl-es-host:9200]][total available: 1; route allocated: 8 of 30; total allocated: 8 of 30]

    If you'd like I can share this debug/trace as a whole. I have sanitized it and compressed into a tar.gz. It is 15.2MB. Let me know if you'd like it and if you'd prefer it to be sent a different way than a github issue attachment?

    For now I'll leave you with all this. Thanks for your time!

  19. pinned this issue on Dec 4, 2025
  20. unpinned this issue on Dec 4, 2025
  21. l-trotta commented on Dec 4, 2025

    @l-trotta
    Contributor

    @marcreichman-pfi Thanks again for all the provided information. It's weird because I can reproduce everything that is happening on your side, except for shutting down the IO reactor. Though I did realize something, and this may sound silly that I only noticed this today, but if the OOM error is being thrown by the request producer, then of course the SafeResponseConsumer won't handle that, since it only works for responses! I need to figure out first why this safety mechanism was only dedicated to responses, and see if it makes sense to add it to requests handling too... in addition to finding out why I can't get it to shut down locally.

  22. marcreichman-pfi commented on Dec 4, 2025

    @marcreichman-pfi
    Author

    Thanks @l-trotta - I did happen to notice that too in this comment. I think if you can produce OOM in the entity producing side (low heap, large bulks with concurrent requests) you should be able to get into this situation pretty easily.

    I think if the MultiBufferEntity code (or the entity producer calling it) can detect this, it may be able to not let the OOM get all the way out to the bottom of the JDK thread. I feel that catching OutOfMemoryError, or Error at all, is bad practice, so I'm not sure what the best course of action is. It also makes me wonder if there is any avenue for more aggressive cleanup, or reduction in copies, in any of that entity producing path, to help alleviate the heap pressure.

    For now, I should be able to run this particular system with a slightly larger heap, and/or less aggressive bulk ingester settings, to work around it now that I understand the scenario moreso. Hopefully you figure out a solution satisfactory to you and the overall project. Thanks again for your time and attention!

  23. l-trotta commented on Dec 19, 2025

    @l-trotta
    Contributor

    Hello @marcreichman-pfi, I did some research on why we don't have the same safety mechanism for requests, and it's simply because for responses the users' application has no control over the size of payloads, so it's more difficult to avoid reactor deaths in case of large payloads in responses, while for requests, it's better for users to regulate the application's throughput then to rely on safety mechanisms. So the client won't implement a SafeRequestConsumer, but! I do have good news.

    Knowing that the same application with the same resources that used to work with an 8.x client version suddenly goes out of memory with 9.x and rest5 made me suspect something wrong was happening with the rest5 client, and I think I might have found the cause, if I'm right this fix will cut memory consumption by half (which should solve your issue). I'll do more testing and will update soon! Thank you for your patience.

  24. marcreichman-pfi commented on Dec 22, 2025

    @marcreichman-pfi
    Author

    @l-trotta Thanks for your persistence! It does seem like the newer client is "heavier" so I'm curious what you find.

  25. l-trotta commented on Jan 9, 2026

    @l-trotta
    Contributor

    Hey @marcreichman-pfi, versions 9.0.9, 9.1.10 and 9.2.4 are out with the fix!

  26. marcreichman-pfi commented on Jan 13, 2026

    @marcreichman-pfi
    Author

    @l-trotta Thank you! I will give it a try shortly. Looks like a good fix.

  27. marcreichman-pfi commented on Jan 15, 2026

    @marcreichman-pfi
    Author

    @l-trotta I tried to beat this up pretty well with my original heap size. I have not been able to blow it up in my usual pattern. I understand that if something throws certain types of Error/Exception on the entity preparation side we may still have this scenario occur, but knowing of it is half the battle.. :)

    Thanks again for your continued investigation into this issue! I think we can close it, hopefully for good this time. 😄

  28. l-trotta commented on Jan 15, 2026

    @l-trotta
    Contributor

    @marcreichman-pfi good to hear! thank you for helping me through this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions