# Connection issues to ES cluster from .NET (System.Net.Sockets.SocketException)

**URL:** <https://discuss.elastic.co/t/connection-issues-to-es-cluster-from-net-system-net-sockets-socketexception/46885>\
**Category:** Elasticsearch\
**Created:** [April 10, 2016, 4:33am UTC](https://discuss.elastic.co/t/connection-issues-to-es-cluster-from-net-system-net-sockets-socketexception/46885 "2016-04-10T04:33:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tejas\_Vora](https://avatars.discourse-cdn.com/v4/letter/t/f17d59/32.png) [@Tejas\_Vora](https://discuss.elastic.co/u/Tejas_Vora)\
**Post date:** [April 10, 2016, 4:33am UTC](https://discuss.elastic.co/t/connection-issues-to-es-cluster-from-net-system-net-sockets-socketexception/46885/1 "2016-04-10T04:33:54Z")

</div>

We are using 3 data nodes, 3 master nodes, 2 client nodes as elastic cluster in Azure. We have an NGINX sitting in front of client nodes to proxy the data.

ES version: 2.2  
NEST: 2.1.0

I am trying to connect from .NET application using NEST library and run simple GET query to retrieve a document using Id. Every now and then, the ES queries fails with the `System.Net.Sockets.SocketException` with error message: "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond XX.XX.XX.XX:9200.".

I tried with following scenario as well.

- Remove NGINX from the path and directly connect to Client nodes. Only Azure Load Balancer in front of client nodes. - Same problem.
- Use native `HttpClient` instead of using `NEST` library - same problem.
- Tweak connection settings on Elastic Client - same problem.

Currently, I am using Static Connection pool following connection settings.

```auto
            var staticPool = new StaticConnectionPool(new[] {new Uri("http://es-url:9200")});
            var connection = new HttpConnection();
            var settings = new ConnectionSettings(staticPool, connection);
            settings = settings.EnableTcpKeepAlive(TimeSpan.FromMilliseconds(2000)
                               .TimeSpan.FromMilliseconds(2000))
                               .RequestTimeout(TimeSpan.FromMinutes(10))
                               .MaximumRetries(10)
                               .DisableAutomaticProxyDetection()
                               .DisableDirectStreaming()
                               .MaxRetryTimeout(TimeSpan.FromMinutes(10))
                               .EnableHttpCompression()
                               .DisablePing();

```

Any suggestions? This is a blocking issue on our side as connection attempt to ES fails with above mentioned exception at constant rate and we would like to solve this problem as soon as possible.

Tejas

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [April 10, 2016, 9:09pm UTC](https://discuss.elastic.co/t/connection-issues-to-es-cluster-from-net-system-net-sockets-socketexception/46885/2 "2016-04-10T21:09:17Z")

</div>

Based on what you have tried (using NEST and HttpClient), this _sounds_ like an issue with the network.

A couple of things to try:

1. What happens if you use [`SingleNodeConnectionPool`](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/connection-pooling.html#single-node-connection-pool) instead of [`StaticConnectionPool`](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/connection-pooling.html#static-connection-pool)? Since you're only configuring one Uri, you don't need the reseeding ability of `StaticConnectionPool`.

2. Can you monitor TCP connections on the client box with [TCPView](https://technet.microsoft.com/en-us/sysinternals/tcpview.aspx) and also look at enabling [Network tracing](https://msdn.microsoft.com/en-us/library/a6sbz1dx(v=vs.110).aspx) on your .NET application to capture more information about what is happening at the network level; NEST and [Elasticsearch.Net](http://Elasticsearch.Net) use [HttpWebRequest](https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(v=vs.110).aspx) under the covers so [configuring tracing for System.Net](https://msdn.microsoft.com/en-us/library/ty48b824(v=vs.110).aspx) should provide more details.

---

<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 5, 2017, 11:00pm UTC](https://discuss.elastic.co/t/connection-issues-to-es-cluster-from-net-system-net-sockets-socketexception/46885/3 "2017-07-05T23:00:53Z")

</div>


