# Elasticsearch connection close issue

**URL:** <https://discuss.elastic.co/t/elasticsearch-connection-close-issue/295581>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [January 27, 2022, 12:30pm UTC](https://discuss.elastic.co/t/elasticsearch-connection-close-issue/295581 "2022-01-27T12:30:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ram\_N](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_n/32/97770_2.png) [@Ram\_N](https://discuss.elastic.co/u/Ram_N)\
**Post date:** [January 27, 2022, 12:30pm UTC](https://discuss.elastic.co/t/elasticsearch-connection-close-issue/295581/1 "2022-01-27T12:30:35Z")

</div>

Hi

Im using 7.10.2 and I have closed Elasticsearch Client while stopping application as below.

```auto
   @PreDestroy
    public void onShutdown(){
		getEsClient().shutdownES();
	     
       
    }

```

But Still Im getting below error in logs while stopping application

```auto
Jan 27, 2022 5:52:45 PM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [amdashboard] created a ThreadLocal with key of type [java.lang.ThreadLocal.SuppliedThreadLocal] (value [java.lang.ThreadLocal$SuppliedThreadLocal@54dc72ea]) and a value of type [org.elasticsearch.common.util.concurrent.ThreadContext.ThreadContextStruct] (value [org.elasticsearch.common.util.concurrent.ThreadContext$ThreadContextStruct@3bb6972a]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jan 27, 2022 5:52:45 PM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [amdashboard] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@2cc43f8a]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@5c168f93]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jan 27, 2022 5:52:45 PM org.apache.coyote.AbstractProtocol stop

```

---

<div class="post-metadata">

**Author:** ![Ram\_N](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_n/32/97770_2.png) [@Ram\_N](https://discuss.elastic.co/u/Ram_N)\
**Post date:** [January 31, 2022, 9:20am UTC](https://discuss.elastic.co/t/elasticsearch-connection-close-issue/295581/2 "2022-01-31T09:20:10Z")

</div>

Can someone please update?

---

<div class="post-metadata">

**Author:** ![Ram\_N](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_n/32/97770_2.png) [@Ram\_N](https://discuss.elastic.co/u/Ram_N)\
**Post date:** [February 7, 2022, 11:34am UTC](https://discuss.elastic.co/t/elasticsearch-connection-close-issue/295581/3 "2022-02-07T11:34:17Z")

</div>

Can someone please update?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 8, 2022, 1:56pm UTC](https://discuss.elastic.co/t/elasticsearch-connection-close-issue/295581/4 "2022-02-08T13:56:21Z")

</div>

Hey,

the `shutdownES()` method does not exist in the Elasticsearch client - where does it come from?

--Alex

---

<div class="post-metadata">

**Author:** ![Ram\_N](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_n/32/97770_2.png) [@Ram\_N](https://discuss.elastic.co/u/Ram_N)\
**Post date:** [February 14, 2022, 12:25pm UTC](https://discuss.elastic.co/t/elasticsearch-connection-close-issue/295581/5 "2022-02-14T12:25:22Z")

</div>

> [@spinscale](#):
>
> the `shutdownES()` method does not exist in the Elasticsearch client - where does it come from?
> 
> --Alex

Its my method. Inside that I call client.close()

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [February 14, 2022, 1:37pm UTC](https://discuss.elastic.co/t/elasticsearch-connection-close-issue/295581/6 "2022-02-14T13:37:50Z")

</div>

Which client are you using exactly? This sounds like a bug, but I think it can only happen if you're using something deprecated. If so, a fix is unlikely, the solution would be to move to a client that isn't deprecated.

---

<div class="post-metadata">

**Author:** ![Ram\_N](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ram_n/32/97770_2.png) [@Ram\_N](https://discuss.elastic.co/u/Ram_N)\
**Post date:** [February 14, 2022, 1:52pm UTC](https://discuss.elastic.co/t/elasticsearch-connection-close-issue/295581/7 "2022-02-14T13:52:39Z")

</div>

Im using 7.10.2 with below code to open and close client

```auto
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;

Client esClient = new TransportClient()
						.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"),9300));
    	esClient.close();

```

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [February 14, 2022, 2:07pm UTC](https://discuss.elastic.co/t/elasticsearch-connection-close-issue/295581/8 "2022-02-14T14:07:36Z")

</div>

> [@Ram\_N](#):
>
> `Client esClient = new TransportClient()`

That confirms it, you're using a [deprecated](https://www.elastic.co/guide/en/elasticsearch/client/java-api/7.10/transport-client.html) client.

---

<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:** [March 14, 2022, 2:07pm UTC](https://discuss.elastic.co/t/elasticsearch-connection-close-issue/295581/9 "2022-03-14T14:07:50Z")

</div>

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