Getting this error - java.util.concurrent.CancellationException: Request execution cancelled

I am facing this issue, where my app tried to send search requests to es and encounters this issue.
my client config is -

> RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(elasticSearchProps.getHost(),
>             elasticSearchProps.getPort(), elasticSearchProps.getScheme()));
> 
>     restClientBuilder.setCompressionEnabled(true);
> 
>     
>     if (elasticSearchProps.getAuthenticationRequired()) {
>       final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
> 
>       credentialsProvider.setCredentials(AuthScope.ANY,
>               new UsernamePasswordCredentials(elasticSearchProps.getUsername(), elasticSearchProps.getPassword()));
> 
>       restClientBuilder.setHttpClientConfigCallback(
>               httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
>     }
> 
>     ElasticsearchTransport transport = new RestClientTransport(restClientBuilder.build(), new JacksonJsonpMapper());
> 
>     RequestConfig requestConfig = RequestConfig.DEFAULT;
>     RequestOptions.Builder requestOptionsBuilder = RequestOptions.DEFAULT
>             .toBuilder()
>             .setRequestConfig(requestConfig);
> 
>     requestOptionsBuilder.setHttpAsyncResponseConsumerFactory(
>             new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(
>                     104857600
>             )
>     );
> 
>     return new ElasticsearchClient(transport, new RestClientOptions(requestOptionsBuilder.build()));

The no. of request being made is considerably high.
How ever there are other search operation, delete, index operations that are working but I am getting this error from a method where i am search the index with track total hits as true to get total count of the doc matching the query.
Am i doing something wrong here?

implementation("co.elastic.clients:elasticsearch-java:8.5.2")
elastic clustor version - 8.5.2

This exception happens when the http client encountered an Error (and not only an Exception) when calling a response listener. A frequent cause for this is an OutOfMemoryError happening in these listeners.

The upcoming version 8.12 contains a protection against this that reports such errors to the application using a custom response consumer factory. The documentation explains how to use it with previous versions of the Java API client.

I added the SafeConsumerResponse file in my project and configured the transport to use the SafeConsumerRepsonse.Default_Options as mentioned in the document.

I still see the same error in the logs on aplication startup.
You mentioned this issue can be caused by OutOfMemoryError, but i dont see any logs indication this. Could the error be because of something else?
Adding some stack trace where I am getting the Request execution cancelled.

extendedStackTrace":
"java.util.concurrent.CancellationException: Request execution cancelled\n\tat 
org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase.execute(CloseableHttpAsyncClientBase.java:114) ~[httpasyncclient-4.1.5.jar:4.1.5]\n\tat 
org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:138) ~[httpasyncclient-4.1.5.jar:4.1.5]\n\tat 
org.elasticsearch.client.RestClient.performRequest(RestClient.java:296) ~[elasticsearch-rest-client-8.5.2.jar:8.5.2]\n\tat 
org.elasticsearch.client.RestClient.performRequest(RestClient.java:288) ~[elasticsearch-rest-client-8.5.2.jar:8.5.2]\n\tat 
co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:147) ~[elasticsearch-java-8.5.2.jar:?]\n\tat 
co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:1518) ~[elasticsearch-java-8.5.2.jar:?]\n\tat

new tranport confid in es bean -

    RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(elasticSearchProps.getHost(),
            elasticSearchProps.getPort(), elasticSearchProps.getScheme()));

    restClientBuilder.setCompressionEnabled(true);

    // Add credentials provider if auth is required
    if (elasticSearchProps.getAuthenticationRequired()) {
      final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();



      credentialsProvider.setCredentials(AuthScope.ANY,
              new UsernamePasswordCredentials(elasticSearchProps.getUsername(), elasticSearchProps.getPassword()));

      restClientBuilder.setHttpClientConfigCallback(
              httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
    }

    RestClientOptions options = new RestClientOptions(
            SafeResponseConsumer.DEFAULT_REQUEST_OPTIONS
    );
    RestClientTransport transport = new RestClientTransport(
            restClientBuilder.build(), new JacksonJsonpMapper(), options
    );

//    ElasticsearchTransport transport = new RestClientTransport(restClientBuilder.build(), new JacksonJsonpMapper());

    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectionRequestTimeout(elasticSearchProps.getConnectionTimeOut())
            .setSocketTimeout(elasticSearchProps.getSocketTimeOut())
            .build();

    RequestOptions.Builder requestOptionsBuilder = RequestOptions.DEFAULT
            .toBuilder()
            .setRequestConfig(requestConfig);

    requestOptionsBuilder.setHttpAsyncResponseConsumerFactory(
            new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(
                    104857600
            )
    );

    return new ElasticsearchClient(transport, new RestClientOptions(requestOptionsBuilder.build()));

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.