Search code examples
pythonelasticsearchdjango-haystack

Using sniffing with python elasticsearch client to solve dead TCP connection issues


The Python elasticsearch client in my applicaiton is having connectivity issues (refused connections) because idle TCP connections timeout due to a firewall (I have no way to prevent this).

The easiest way for me to fix this would be if I could prevent the connection from going idle by sending some data over it periodically, the sniffing options in the elasticsearch client seem ideal for this, however they're not very well documented:

sniff_on_start – flag indicating whether to obtain a list of nodes from the cluser at startup time

sniffer_timeout – number of seconds between automatic sniffs

sniff_on_connection_fail – flag controlling if connection failure triggers a sniff

sniff_timeout – timeout used for the sniff request - it should be a fast api call and we are talking potentially to more nodes so we want to fail quickly. Not used during initial sniffing (if sniff_on_start is on) when the connection still isn’t initialized.

What I would like is for the client to sniff every (say) 5 minutes, should I be using the sniff_timeout or sniffer_timeout option? Also, should the sniff_on_start parameter be set to True?


Solution

  • I used the suggestion from @val and found that these settings solved my problem:

    sniff_on_start=True
    sniffer_timeout=60
    sniff_on_connection_fail=True
    

    The sniffing puts enough traffic on the TCP connections so that they are never idle for long enough for our firewall to kill the conneciton.