# Intermittent exception in index call

**URL:** <https://discuss.elastic.co/t/intermittent-exception-in-index-call/340903>\
**Category:** Elasticsearch\
**Tags:** docker, language-clients\
**Created:** [August 16, 2023, 11:15am UTC](https://discuss.elastic.co/t/intermittent-exception-in-index-call/340903 "2023-08-16T11:15:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luiz\_Basile](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luiz_basile/32/122632_2.png) [@Luiz\_Basile](https://discuss.elastic.co/u/Luiz_Basile)\
**Post date:** [August 16, 2023, 11:15am UTC](https://discuss.elastic.co/t/intermittent-exception-in-index-call/340903/1 "2023-08-16T11:15:44Z")

</div>

We are using Elasticsearch java, in a lambda function. The below log is in lambda  
Apparently this exception is happening when you use the Elastic of other component and quickly trigger the lambda function. Any suggestions?

```auto
Request execution cancelled: java.lang.RuntimeException
java.lang.RuntimeException: Request execution cancelled
	at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:938)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:300)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:288)
	at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:153)
	at co.elastic.clients.elasticsearch.ElasticsearchClient.index(ElasticsearchClient.java:1067)
	at co.elastic.clients.elasticsearch.ElasticsearchClient.index(ElasticsearchClient.java:1084)
	...
Caused by: java.util.concurrent.CancellationException: Request execution cancelled
	at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase.execute(CloseableHttpAsyncClientBase.java:114)
	at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:138)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:296)

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Luiz\_Basile](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luiz_basile/32/122632_2.png) [@Luiz\_Basile](https://discuss.elastic.co/u/Luiz_Basile)\
**Post date:** [September 1, 2023, 3:53pm UTC](https://discuss.elastic.co/t/intermittent-exception-in-index-call/340903/2 "2023-09-01T15:53:14Z")

</div>

I managed to solve this by myself. The problem was that I was opening a connection with Elastic Search and never closing it.

So actually was working only for the first time and when trigger for the second that I already had the connection opened this problem happened.

The solution in this case was making sure every connection with ES has been closed after using it.

---

<div class="post-metadata">

**Author:** ![hr89](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hr89/32/116836_2.png) [@hr89](https://discuss.elastic.co/u/hr89)\
**Post date:** [September 4, 2023, 4:06pm UTC](https://discuss.elastic.co/t/intermittent-exception-in-index-call/340903/3 "2023-09-04T16:06:00Z")

</div>

@Luiz_Basile  
Getting similar exception. Can you explain and show some code snippet that how are you "closing the connection?"

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 2, 2023, 4:06pm UTC](https://discuss.elastic.co/t/intermittent-exception-in-index-call/340903/4 "2023-10-02T16:06:57Z")

</div>

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