From 1f7aaaadf1095d4fefbc52290b1a75ff762a5e37 Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Mon, 19 Oct 2026 08:37:39 +0000 Subject: [PATCH 1/2] Keep safe response consumer when converting transport options RestClientOptions.of() and Rest5ClientOptions.of() built converted options from RequestOptions.DEFAULT, so options set with the client builder's transportOptions() or retryConfig(), or passed as DefaultTransportOptions, lost the SafeResponseConsumer that prevents I/O reactor shutdowns. Start from SafeResponseConsumer.DEFAULT_REQUEST_OPTIONS instead, as initialOptions() does. --- .../rest5_client/Rest5ClientOptions.java | 2 +- .../transport/rest_client/RestClientOptions.java | 2 +- .../rest5_client/Rest5ClientOptionsTest.java | 15 +++++++++++++++ .../rest_client/RestClientOptionsTest.java | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/java-client/src/main/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptions.java b/java-client/src/main/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptions.java index 6f4f745297..7798fcd1d9 100644 --- a/java-client/src/main/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptions.java +++ b/java-client/src/main/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptions.java @@ -61,7 +61,7 @@ public static Rest5ClientOptions of(@Nullable TransportOptions options) { return (Rest5ClientOptions) options; } - final Builder builder = new Builder(RequestOptions.DEFAULT.toBuilder()); + final Builder builder = new Builder(SafeResponseConsumer.DEFAULT_REQUEST_OPTIONS.toBuilder()); options.headers().forEach(h -> builder.addHeader(h.getKey(), h.getValue())); options.queryParameters().forEach(builder::setParameter); builder.onWarnings(options.onWarnings()); diff --git a/java-client/src/main/java/co/elastic/clients/transport/rest_client/RestClientOptions.java b/java-client/src/main/java/co/elastic/clients/transport/rest_client/RestClientOptions.java index 431a9cbd44..a3b866d5bc 100644 --- a/java-client/src/main/java/co/elastic/clients/transport/rest_client/RestClientOptions.java +++ b/java-client/src/main/java/co/elastic/clients/transport/rest_client/RestClientOptions.java @@ -61,7 +61,7 @@ public static RestClientOptions of(@Nullable TransportOptions options) { return (RestClientOptions)options; } - final Builder builder = new Builder(RequestOptions.DEFAULT.toBuilder()); + final Builder builder = new Builder(SafeResponseConsumer.DEFAULT_REQUEST_OPTIONS.toBuilder()); options.headers().forEach(h -> builder.addHeader(h.getKey(), h.getValue())); options.queryParameters().forEach(builder::setParameter); builder.onWarnings(options.onWarnings()); diff --git a/java-client/src/test/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptionsTest.java b/java-client/src/test/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptionsTest.java index 439acc08eb..6fb5a1e4be 100644 --- a/java-client/src/test/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptionsTest.java +++ b/java-client/src/test/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptionsTest.java @@ -199,4 +199,19 @@ void testRequestOptionsOverridingBuiltin() throws Exception { // overriding user-agent is ok checkUserAgent(id, "FooBarAgent/1.0"); } + + @Test + void testConvertedOptionsUseSafeResponseConsumer() throws Exception { + // Transport options set on the client builder are converted from DefaultTransportOptions + ElasticsearchClient esClient = ElasticsearchClient.of(b -> b + .host("http://example.com") + .transportOptions(o -> o.addHeader("Foo", "bar")) + ); + + Rest5ClientOptions options = (Rest5ClientOptions) esClient._transportOptions(); + assertSame(SafeResponseConsumer.DEFAULT_FACTORY, + options.restClientRequestOptions().getHttpAsyncResponseConsumerFactory()); + + esClient._transport().close(); + } } diff --git a/java-client/src/test/java/co/elastic/clients/transport/rest_client/RestClientOptionsTest.java b/java-client/src/test/java/co/elastic/clients/transport/rest_client/RestClientOptionsTest.java index cf89959442..08d47b19af 100644 --- a/java-client/src/test/java/co/elastic/clients/transport/rest_client/RestClientOptionsTest.java +++ b/java-client/src/test/java/co/elastic/clients/transport/rest_client/RestClientOptionsTest.java @@ -199,4 +199,20 @@ void testRequestOptionsOverridingBuiltin() throws Exception { // overriding user-agent is ok checkUserAgent(id, "FooBarAgent/1.0"); } + + @Test + void testConvertedOptionsUseSafeResponseConsumer() throws Exception { + // Transport options set on the client builder are converted from DefaultTransportOptions + ElasticsearchClient esClient = ElasticsearchClient.of(b -> b + .host("http://example.com") + .useLegacyTransport(true) + .transportOptions(o -> o.addHeader("Foo", "bar")) + ); + + RestClientOptions options = (RestClientOptions) esClient._transportOptions(); + assertSame(SafeResponseConsumer.DEFAULT_FACTORY, + options.restClientRequestOptions().getHttpAsyncResponseConsumerFactory()); + + esClient._transport().close(); + } } From e64328698501c0d1e0ba7c38c7c5ba84d32d9900 Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Fri, 6 Nov 2026 20:30:55 +0000 Subject: [PATCH 2/2] Close the test clients with try-with-resources --- .../rest5_client/Rest5ClientOptionsTest.java | 14 ++++++-------- .../rest_client/RestClientOptionsTest.java | 14 ++++++-------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/java-client/src/test/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptionsTest.java b/java-client/src/test/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptionsTest.java index 6fb5a1e4be..3228cfa7dd 100644 --- a/java-client/src/test/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptionsTest.java +++ b/java-client/src/test/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptionsTest.java @@ -203,15 +203,13 @@ void testRequestOptionsOverridingBuiltin() throws Exception { @Test void testConvertedOptionsUseSafeResponseConsumer() throws Exception { // Transport options set on the client builder are converted from DefaultTransportOptions - ElasticsearchClient esClient = ElasticsearchClient.of(b -> b + try (ElasticsearchClient esClient = ElasticsearchClient.of(b -> b .host("http://example.com") .transportOptions(o -> o.addHeader("Foo", "bar")) - ); - - Rest5ClientOptions options = (Rest5ClientOptions) esClient._transportOptions(); - assertSame(SafeResponseConsumer.DEFAULT_FACTORY, - options.restClientRequestOptions().getHttpAsyncResponseConsumerFactory()); - - esClient._transport().close(); + )) { + Rest5ClientOptions options = (Rest5ClientOptions) esClient._transportOptions(); + assertSame(SafeResponseConsumer.DEFAULT_FACTORY, + options.restClientRequestOptions().getHttpAsyncResponseConsumerFactory()); + } } } diff --git a/java-client/src/test/java/co/elastic/clients/transport/rest_client/RestClientOptionsTest.java b/java-client/src/test/java/co/elastic/clients/transport/rest_client/RestClientOptionsTest.java index 08d47b19af..29f73cf984 100644 --- a/java-client/src/test/java/co/elastic/clients/transport/rest_client/RestClientOptionsTest.java +++ b/java-client/src/test/java/co/elastic/clients/transport/rest_client/RestClientOptionsTest.java @@ -203,16 +203,14 @@ void testRequestOptionsOverridingBuiltin() throws Exception { @Test void testConvertedOptionsUseSafeResponseConsumer() throws Exception { // Transport options set on the client builder are converted from DefaultTransportOptions - ElasticsearchClient esClient = ElasticsearchClient.of(b -> b + try (ElasticsearchClient esClient = ElasticsearchClient.of(b -> b .host("http://example.com") .useLegacyTransport(true) .transportOptions(o -> o.addHeader("Foo", "bar")) - ); - - RestClientOptions options = (RestClientOptions) esClient._transportOptions(); - assertSame(SafeResponseConsumer.DEFAULT_FACTORY, - options.restClientRequestOptions().getHttpAsyncResponseConsumerFactory()); - - esClient._transport().close(); + )) { + RestClientOptions options = (RestClientOptions) esClient._transportOptions(); + assertSame(SafeResponseConsumer.DEFAULT_FACTORY, + options.restClientRequestOptions().getHttpAsyncResponseConsumerFactory()); + } } }