# Getting ConnectionPoolTimeoutException while calling Elastic search cluster

**URL:** <https://discuss.elastic.co/t/getting-connectionpooltimeoutexception-while-calling-elastic-search-cluster/245388>\
**Category:** Elasticsearch\
**Created:** [August 18, 2020, 10:17am UTC](https://discuss.elastic.co/t/getting-connectionpooltimeoutexception-while-calling-elastic-search-cluster/245388 "2020-08-18T10:17:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![itsanviv](https://avatars.discourse-cdn.com/v4/letter/i/919ad9/32.png) [@itsanviv](https://discuss.elastic.co/u/itsanviv)\
**Post date:** [August 18, 2020, 10:17am UTC](https://discuss.elastic.co/t/getting-connectionpooltimeoutexception-while-calling-elastic-search-cluster/245388/1 "2020-08-18T10:17:06Z")

</div>

Hello,  
We are getting ConnectionPoolTimeoutException while calling elastic search for update and get query. We are using aws elastic search services. We are using Jest client and configuration are below.

```auto
 public final class JestClientFactory {

    private JestClientFactory() {
    }

    public static final int READ_TIME_OUT = 60000;
    public static final int MAX_TOTAL_CONNS = 40;
    public static final int DEFAULT_MAX_TOTAL_CONNECTION_PER_ROUTE = 4;

    public static JestClient getClient(final String esEndpoint, final String awsRegion, final String odinMaterialSet) {
        final HttpClientConfig httpClientConfig = new HttpClientConfig.Builder(esEndpoint)
                                                                      .multiThreaded(true)
                                                                      .readTimeout(READ_TIME_OUT)
                                                                      .defaultMaxTotalConnectionPerRoute(DEFAULT_MAX_TOTAL_CONNECTION_PER_ROUTE)
                                                                      .maxTotalConnection(MAX_TOTAL_CONNS)
                                                                      .build();

        final AESClientFactory aesClientFactory = new AESClientFactory(getAwsCredentialsProvier(odinMaterialSet),
                awsRegion);
        aesClientFactory.setHttpClientConfig(httpClientConfig);
        final JestClient jestClient = aesClientFactory.getObject();
        return jestClient;
    }

    private static AWSCredentialsProvider getAwsCredentialsProvier(final String odinMaterialSetValue) {
        return new OdinAWSCredentialsProvider(odinMaterialSetValue);
    }
}

```

Complete logs for error which we are getting are below -

```auto
application.log.2020-08-06-16.es-analytics-eu-prod-1a-1106f343.eu-west-1.amazon.com.gz:Caused by: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
application.log.2020-08-06-16.es-analytics-eu-prod-1a-1106f343.eu-west-1.amazon.com.gz:	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:314) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?]
application.log.2020-08-06-16.es-analytics-eu-prod-1a-1106f343.eu-west-1.amazon.com.gz:	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$1.get(PoolingHttpClientConnectionManager.java:280) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?]
application.log.2020-08-06-16.es-analytics-eu-prod-1a-1106f343.eu-west-1.amazon.com.gz:	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:190) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?]
application.log.2020-08-06-16.es-analytics-eu-prod-1a-1106f343.eu-west-1.amazon.com.gz:	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?]
application.log.2020-08-06-16.es-analytics-eu-prod-1a-1106f343.eu-west-1.amazon.com.gz:	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?]
application.log.2020-08-06-16.es-analytics-eu-prod-1a-1106f343.eu-west-1.amazon.com.gz:	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?]
application.log.2020-08-06-16.es-analytics-eu-prod-1a-1106f343.eu-west-1.amazon.com.gz:	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?]
application.log.2020-08-06-16.es-analytics-eu-prod-1a-1106f343.eu-west-1.amazon.com.gz:	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?]
application.log.2020-08-06-16.es-analytics-eu-prod-1a-1106f343.eu-west-1.amazon.com.gz:	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?]
application.log.2020-08-06-16.es-analytics-eu-prod-1a-1106f343.eu-west-1.amazon.com.gz:	at io.searchbox.client.http.JestHttpClient.executeRequest(JestHttpClient.java:109) ~[Jest-2.0.3.jar:?]
application.log.2020-08-06-16.es-analytics-eu-prod-1a-1106f343.eu-west-1.amazon.com.gz:	at io.searchbox.client.http.JestHttpClient.execute(JestHttpClient.java:56) ~[Jest-2.0.3.jar:?]

```

1. Can anyone help to provide better configuration details and how I can avoid this exception?
2. Also not able to find meaning for defaultMaxTotalConnectionPerRoute. Please provide info about this.

---

<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:** [September 15, 2020, 10:17am UTC](https://discuss.elastic.co/t/getting-connectionpooltimeoutexception-while-calling-elastic-search-cluster/245388/2 "2020-09-15T10:17:08Z")

</div>

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