libvmod-dynamic icon indicating copy to clipboard operation
libvmod-dynamic copied to clipboard

Add resolver fallback to the null resolver (getaddrinfo)

Open delthas opened this issue 2 years ago • 2 comments

This enables a best-effort, two-step resolution when a resolver is configured:

  • if the DNS resolver returns any domain, that record is used with its corresponding TTL
  • otherwise, the module tries resolving the name with the default, NULL resolver, which is just a wrapper over getaddrinfo
    • if the resolution succeeds, this was likely a domain in /etc/hosts or an IP literal, which was not known by the DNS server. The associated record has no TTL value and uses the default director TTL.
    • if the resolution fails, this was likely a bad domain. No records are stored and a new request is made after the default director TTL, as was done previously.

The patch is somewhat dumb, it just wraps the resolve logic in a loop that can iterate twice. The goal was to minimize the size of git diff -w.

This causes the module to log Lookup & Results & Error twice in case we do the fallback attempt, which could be a nice side-effect (we can investigate a DNS error in varnishlog but see that it still succeeded). I don't have a strong opinion about this one.

Feel free to amend and merge if you'd like. Otherwise I can make changes. :smile:

delthas avatar Jul 25 '23 12:07 delthas

Thank you for your work on this!

Regarding the implementation, I would actually like to see if we can avoid the additional while block. As you already said you'd be fine with amending, I would just do that.

But, more importantly:

  • Shouldn't we make the fallback optional? I fear there might be cases where /etc/hosts in particular should not be used.
  • Or should we even go one step further and support a list of resolvers to try?

nigoroll avatar Jul 25 '23 19:07 nigoroll

Hi @delthas, are you still interested in this patch? If yes, I would be interested in your opinion about my two questions:

  • Shouldn't we make the fallback optional? I fear there might be cases where /etc/hosts in particular should not be used.

  • Or should we even go one step further and support a list of resolvers to try?

nigoroll avatar Jan 28 '24 19:01 nigoroll