# Seeing many open Elasticsearch connections even after using singleton pattern

**URL:** https://discuss.elastic.co/t/seeing-many-open-elasticsearch-connections-even-after-using-singleton-pattern/21919
**Category:** Elasticsearch
**Created:** [January 30, 2015, 11:12am UTC](https://discuss.elastic.co/t/seeing-many-open-elasticsearch-connections-even-after-using-singleton-pattern/21919 "2015-01-30T11:12:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![prachicsa](https://avatars.discourse-cdn.com/v4/letter/p/f4b2a3/32.png) [@prachicsa](https://discuss.elastic.co/u/prachicsa)
#### Post date: [January 30, 2015, 11:12am UTC](https://discuss.elastic.co/t/seeing-many-open-elasticsearch-connections-even-after-using-singleton-pattern/21919/1 "2015-01-30T11:12:07Z")

</div>

Hi,

I just the following method for connection creation in ES:

```
public static Client getClient() {
    if (client == null) {
        synchronized (mutex) {
            settings = 

```

ImmutableSettings.settingsBuilder().put(CONFIG\_CLUSTER\_NAME,  
CLUSTER\_NAME).build();  
client = new TransportClient(settings);  
for (String address : transportAddress ) {  
((TransportClient) client).addTransportAddress(new  
InetSocketTransportAddress(address, transportPort));  
}  
logger.info("Elastic search client initialized");  
}  
}  
logger.info("Returning the existing client");  
return client;  
}

But for this application, when I ran `netstat` on that host, I saw many  
open connections:

```
tcp 0 0 ::ffff:*.*.*.*:59380 ::ffff:*.*.*.*:9300   

```

ESTABLISHED 6552/java  
tcp 0 0 ::ffff:_._._._:48829 ::ffff:_._._._:9300  
ESTABLISHED 6552/java  
tcp 0 0 ::ffff:_._._._:42944 ::ffff:_._._._:9300  
TIME\_WAIT -  
tcp 0 0 ::ffff:_._._._:42838 ::ffff:_._._._:9300  
ESTABLISHED 6552/java  
tcp 0 0 ::ffff:_._._._:8080 ::ffff:_._._._:57649  
ESTABLISHED 6552/java  
tcp 0 0 ::ffff:_._._._:55154 ::ffff:_._._._:3306  
ESTABLISHED 6552/java  
tcp 0 1 ::ffff:_._._._:36889 ::ffff:_._._._:9300  
FIN\_WAIT1 -  
tcp 0 0 ::ffff:_._._._:42829 ::ffff:_._._._:9300  
ESTABLISHED 6552/java  
tcp 0 0 ::ffff:_._._._:37169 ::ffff:_._._._:9300  
TIME\_WAIT -  
tcp 0 0 ::ffff:_._._._:59390 ::ffff:_._._._:9300  
ESTABLISHED 6552/java  
tcp 0 0 ::ffff:_._._._:58283 ::ffff:_._._._:9300  
TIME\_WAIT -  
tcp 0 0 ::ffff:_._._._:59383 ::ffff:_._._._:9300  
ESTABLISHED 6552/java  
tcp 0 0 ::ffff:_._._._:55855 ::ffff:_._._._:9300  
TIME\_WAIT -  
tcp 0 0 ::ffff:_._._._:48823 ::ffff:_._._._:9300  
ESTABLISHED 6552/java  
tcp 0 1 ::ffff:_._._._:36884 ::ffff:_._._._:9300  
FIN\_WAIT1 -

I have removed the ip with _._._._. But there are many more open  
connections than this.

Questions:  
-\> How do I manually go and close all these connections?  
-\> Is there any mistake in connection creation?  
-\> Sometimes, even if ES is running and connection is also created, it  
doesn't get any response. After restarting the application, it returns  
result for the same query. How should I analyze this?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0d751233-ad0d-4c70-bdd0-ca3234b28836%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0d751233-ad0d-4c70-bdd0-ca3234b28836%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [July 6, 2017, 12:35am UTC](https://discuss.elastic.co/t/seeing-many-open-elasticsearch-connections-even-after-using-singleton-pattern/21919/2 "2017-07-06T00:35:41Z")

</div>


