szmarczak / cacheable-lookup

A cacheable dns.lookup(…) that respects TTL :tada:
MIT License
193 stars 29 forks source link

fallbackDuration behaviour doesn't match docs #35

Open pimterry opened 3 years ago

pimterry commented 3 years ago

fallbackDuration is documented as:

When the DNS server responds with ENOTFOUND or ENODATA and the OS reports that the entry is available, it will use dns.lookup(...) directly for the requested hostnames for the specified amount of time (in seconds).

In reality, it's not a cache time, it's a periodic reset frequency: https://github.com/szmarczak/cacheable-lookup/blob/da10b58475ab89e944ec112f521e86402c344fc1/source/index.js#L97-L106

For example, if it's set to 1 hour, and then 55 minutes after creating the CacheableLookup instance a hostname lookup fails, the fallback usage will only be cached for 5 minutes (the time until the next reset).

This isn't a big problem for me particularly right now, just something I noticed.

szmarczak commented 3 years ago

Good spot! I must've overlooked this. Will fix this ASAP.