# MaxTimeoutReached occurring after failing to connect via sniffing connection pool

**URL:** <https://discuss.elastic.co/t/maxtimeoutreached-occurring-after-failing-to-connect-via-sniffing-connection-pool/318973>\
**Category:** Elasticsearch\
**Created:** [November 15, 2022, 3:38pm UTC](https://discuss.elastic.co/t/maxtimeoutreached-occurring-after-failing-to-connect-via-sniffing-connection-pool/318973 "2022-11-15T15:38:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hoppities](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hoppities/32/85836_2.png) [@Hoppities](https://discuss.elastic.co/u/Hoppities)\
**Post date:** [November 15, 2022, 3:38pm UTC](https://discuss.elastic.co/t/maxtimeoutreached-occurring-after-failing-to-connect-via-sniffing-connection-pool/318973/1 "2022-11-15T15:38:03Z")

</div>

Whenever we run into this scenario where a sniff happened and elastic was unable to connect, we then see this timeout with a massive negative number.

I'm not even sure where to start with this. Any help would be appreciated.

We're in the process of upgrading elastic, but this is currently happening with 5.6.

Connection Settings

```auto
  var elasticPool = new Elasticsearch.Net.SniffingConnectionPool(nodes);
  elasticSettings = new ConnectionSettings(elasticPool);
  elasticSettings.SniffOnStartup(true)
      .SniffOnConnectionFault(true)
      .SniffLifeSpan(TimeSpan.FromMinutes(30));
      .ConnectionLimit(160)
      .DefaultIndex("jobs")
      .DisableDirectStreaming(true)
      .EnableHttpCompression(true)
      .MaximumRetries(1)
      .RequestTimeout(new TimeSpan(0, 0, 5))
      .ThrowExceptions(true);

```

Response

```auto
Unsuccessful low level call on POST: /index/message%2CmessageChild/_search?routing=ID_GOES_HERE
     # Audit trail of this API call :
     - [1]BadResponse: Node: http: //1.1.1.1:9200/ Took: 00:00:05.0158085
     - [2]SniffOnFail: Took: 00: 00: 00.0060049
     - [3]SniffSuccess: Node: http: //1.1.1.1:9200/ Took: 00:00:00.0060049
     - [4]MaxTimeoutReached: Took: -738460.19: 12: 17.8729319
     # OriginalException: System.Net.WebException: The operation has timed out
    at System.Net.HttpWebRequest.GetResponse()
    at Elasticsearch.Net.HttpWebRequestConnection.Request[TReturn](RequestData requestData)
     # Request: {
    "aggs": {
        "Type": {
            "terms": {
                "field": "type",
                "order": [{
                        "_count": "desc"
                    }
                ],
                "size": 100
            }
        },
        "MessageType": {
            "terms": {
                "field": "messageType",
                "order": [{
                        "_count": "desc"
                    }
                ],
                "size": 100
            }
        },
        "CreatedBy": {
            "terms": {
                "field": "createdBy",
                "order": [{
                        "_count": "desc"
                    }
                ],
                "size": 200
            }
        }
    },
    "from": 0,
    "query": {
        "bool": {
            "must": [{
                    "terms": {
                        "locationId": ["ID_GOES_HERE"]
                    }
                }, {
                    "terms": {
                        "roleId": ["1111111", "11", "111", "1111", "0000001", "0000011", "0000101", "0000111", "0001001", "0001011", "0001101", "0001111", "0010001", "0010011", "0010101", "0010111", "0011001", "0011011", "0011101", "0011111", "0100001", "0100011", "0100101", "0100111", "0101001", "0101011", "0101101", "0101111", "0110001", "0110011", "0110101", "0110111", "0111001", "0111011", "0111101", "0111111"]
                    }
                }, {
                    "terms": {
                        "jobId": ["ID_GOES_HERE"]
                    }
                }, {
                    "bool": {
                        "minimum_should_match": 1,
                        "should": [{
                                "match": {
                                    "_all": {
                                        "max_expansions": 1000,
                                        "prefix_length": 2,
                                        "query": "free",
                                        "type": "phrase_prefix"
                                    }
                                }
                            }, {
                                "has_child": {
                                    "query": {
                                        "match": {
                                            "_all": {
                                                "max_expansions": 1000,
                                                "prefix_length": 2,
                                                "query": "free",
                                                "type": "phrase_prefix"
                                            }
                                        }
                                    },
                                    "type": "messageChild"
                                }
                            }
                        ]
                    }
                }, {
                    "bool": {
                        "must_not": [{
                                "exists": {
                                    "field": "parentMessageId"
                                }
                            }
                        ]
                    }
                }
            ]
        }
    },
    "size": 20,
    "sort": [{
            "createdDate": {
                "order": "desc"
            }
        }
    ]
}

```

---

<div class="post-metadata">

**Author:** ![Hoppities](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hoppities/32/85836_2.png) [@Hoppities](https://discuss.elastic.co/u/Hoppities)\
**Post date:** [November 22, 2022, 7:53pm UTC](https://discuss.elastic.co/t/maxtimeoutreached-occurring-after-failing-to-connect-via-sniffing-connection-pool/318973/2 "2022-11-22T19:53:45Z")

</div>

For anyone that's curious, we figured this out. The issue was the `has_child` search. This is just not a performant query, so we split the query, ran two, and added the ids we needed in the `should` portion of the query.

---

<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:** [December 20, 2022, 7:54pm UTC](https://discuss.elastic.co/t/maxtimeoutreached-occurring-after-failing-to-connect-via-sniffing-connection-pool/318973/3 "2022-12-20T19:54:33Z")

</div>

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