# RestHighLevelClient SocketTimeoutException

**URL:** <https://discuss.elastic.co/t/resthighlevelclient-sockettimeoutexception/202443>\
**Category:** Elasticsearch\
**Created:** [October 6, 2019, 10:27am UTC](https://discuss.elastic.co/t/resthighlevelclient-sockettimeoutexception/202443 "2019-10-06T10:27:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zharenkov](https://avatars.discourse-cdn.com/v4/letter/z/bcef8e/32.png) [@zharenkov](https://discuss.elastic.co/u/zharenkov)\
**Post date:** [October 6, 2019, 10:27am UTC](https://discuss.elastic.co/t/resthighlevelclient-sockettimeoutexception/202443/1 "2019-10-06T10:27:10Z")

</div>

I've got ES cluster on Azure, and communicate with it from Spring Boot app using elasticsearch RestHighLevelClient.

The bean in spring is the follow

```
@Bean
public RestHighLevelClient elasticsearchRestClient() {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
    return new RestHighLevelClient(RestClient.builder(new HttpHost(ipAddress, port))
            .setRequestConfigCallback(builder -> builder
                    .setConnectTimeout(10000)
                    .setSocketTimeout(90000)
                    .setConnectionRequestTimeout(0)
            )
            .setHttpClientConfigCallback(httpClientBuilder ->
                    httpClientBuilder
                            .setDefaultCredentialsProvider(credentialsProvider)));
}

```

Here ipAddress is loadbalancer's ip on Azure ES cluster, port is 9200. The problem is - if ES idle for few minutes - next request to ES fails with SocketTimeoutException.

`2019-09-26T07:20:50.228101050Z: [INFO] java.net.SocketTimeoutException: 90,000 milliseconds timeout on connection http-outgoing-5 [ACTIVE] 2019-09-26T07:20:50.228104650Z: [INFO] at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:773) ~[elasticsearch-rest-client-7.3.2.jar!/:7.3.2] 2019-09-26T07:20:50.228108350Z: [INFO] at org.elasticsearch.client.RestClient.performRequest(RestClient.java:218) ~[elasticsearch-rest-client-7.3.2.jar!/:7.3.2] 2019-09-26T07:20:50.228111750Z: [INFO] at org.elasticsearch.client.RestClient.performRequest(RestClient.java:205) ~[elasticsearch-rest-client-7.3.2.jar!/:7.3.2] 2019-09-26T07:20:50.228115350Z: [INFO] at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1454) ~[elasticsearch-rest-high-level-client-7.3.2.jar!/:7.3.2] 2019-09-26T07:20:50.228118850Z: [INFO] at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1439) ~[elasticsearch-rest-high-level-client-7.3.2.jar!/:7.3.2] 2019-09-26T07:20:50.228122150Z: [INFO] at org.elasticsearch.client.IndicesClient.exists(IndicesClient.java:784) ~[elasticsearch-rest-high-level-client-7.3.2.jar!/:7.3.2]`

After this fail, retry attemp finishes succesfully.

I've tried to add sniffer on LowLevelRestClient - but no effect.

Also, i tried to add some kind of polling ES every minute like this

```
    @Scheduled(cron = "0 0/1 * * * *")
public void checkHealth() throws IOException {
    LOGGER.info(restHighLevelClient.info(RequestOptions.DEFAULT));
}

```

And in this case - every request works fine. But I believe it's not the best option.

What can be the possible trouble? Thanks!

---

<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:** [November 3, 2019, 10:27am UTC](https://discuss.elastic.co/t/resthighlevelclient-sockettimeoutexception/202443/2 "2019-11-03T10:27:12Z")

</div>

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