# SnifferBuilder.sniffOnFailureListener() not honored

**URL:** <https://discuss.elastic.co/t/snifferbuilder-sniffonfailurelistener-not-honored/110468>\
**Category:** Elasticsearch\
**Created:** [December 6, 2017, 8:27am UTC](https://discuss.elastic.co/t/snifferbuilder-sniffonfailurelistener-not-honored/110468 "2017-12-06T08:27:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eyasso](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@eyasso](https://discuss.elastic.co/u/eyasso)\
**Post date:** [December 6, 2017, 8:27am UTC](https://discuss.elastic.co/t/snifferbuilder-sniffonfailurelistener-not-honored/110468/1 "2017-12-06T08:27:57Z")

</div>

Hi,

I am using elasticsearch-rest-client-sniffer version 5.6.3.  
I am following the example code for getting sniffing nodes health: [Sniffer Usage](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_usage.html)

```
SniffOnFailureListener sniffOnFailureListener = new SniffOnFailureListener();
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200))
    .setFailureListener(sniffOnFailureListener) 
    .build();
Sniffer sniffer = Sniffer.builder(restClient)
    .setSniffAfterFailureDelayMillis(30000) 
    .build();
sniffOnFailureListener.setSniffer(sniffer); 

```

The problem is that I get messages for failed nodes every 5 minutes, which is the default timeout for the sniffer instead of every 30000ms as requested in the above code.  
Am I doing anything wrong?

Thanks

---

<div class="post-metadata">

**Author:** ![eyasso](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@eyasso](https://discuss.elastic.co/u/eyasso)\
**Post date:** [December 6, 2017, 9:24am UTC](https://discuss.elastic.co/t/snifferbuilder-sniffonfailurelistener-not-honored/110468/2 "2017-12-06T09:24:24Z")

</div>

Farther investigation, I think the bug is in method `Sniffer.Task.sniff()`.  
The first call to `Sniffer.Task.sniff()` is done for `setSniffIntervalMillis` timeout which is blocked in `hostsSniffer.sniffHosts()`.  
During that time, for each failed node, `Sniffer.Task.sniff()`is called with `setSniffAfterFailureDelayMillis` timeout. Since the first call is still blocking in `Sniffer.Task.sniff()` it cannot call `scheduleNextRun` because `if (running.compareAndSet(false, true)) {` condition prevents it from. When all failed nodes are sniffed, `hostsSniffer.sniffHosts()` returns and set the time again to `setSniffIntervalMillis`.

I think the in the Exception statement, you should set `nextSniffDelayMillis` to be equal to `sniffAfterFailureDelayMillis`.

I Hope I am not wrong

---

<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:** [January 3, 2018, 9:24am UTC](https://discuss.elastic.co/t/snifferbuilder-sniffonfailurelistener-not-honored/110468/3 "2018-01-03T09:24:47Z")

</div>

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