Skip to content

Transport options set on the client builder drop SafeResponseConsumer #1354

Open

Description

@RaphaelFakhri

Java API client version

main (f920563)

Java version

21

Elasticsearch Version

Any (client-side)

Problem description

RestClientOptions.of() and Rest5ClientOptions.of() convert other TransportOptions implementations starting from RequestOptions.DEFAULT, while initialOptions() starts from SafeResponseConsumer.DEFAULT_REQUEST_OPTIONS. Converted options therefore lose SafeResponseConsumer.

The ElasticsearchClient.of(...) builder methods transportOptions(fn) and retryConfig(...) produce DefaultTransportOptions, so a client configured like this runs without the safe consumer:

ElasticsearchClient client = ElasticsearchClient.of(b -> b
    .host("http://localhost:9200")
    .transportOptions(o -> o.addHeader("Foo", "bar"))
);

Rest5ClientOptions options = (Rest5ClientOptions) client._transportOptions();
// Expected: SafeResponseConsumer.DEFAULT_FACTORY
// Actual:   HttpAsyncResponseConsumerFactory$BasicAsyncResponseConsumerFactory
System.out.println(options.restClientRequestOptions().getHttpAsyncResponseConsumerFactory());

The legacy transport (useLegacyTransport(true)) shows the same behavior with HeapBufferedResponseConsumerFactory. An Error thrown while consuming a response can then stop the I/O reactor, the failure that SafeResponseConsumer prevents (#1046).

Activity

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