Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable cache or refresh it asynchronously #10

Closed
thibmeu opened this issue Oct 6, 2021 · 7 comments · Fixed by #12
Closed

Option to disable cache or refresh it asynchronously #10

thibmeu opened this issue Oct 6, 2021 · 7 comments · Fixed by #12
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@thibmeu
Copy link
Contributor

thibmeu commented Oct 6, 2021

This resolver provides a cache for IP addresses and TXT records.
Depending on the TTL set for the DNS record, this can lead to a significant delay before the resolver returns an up to date DNS record.

If this is done for latency concerns, updating the cache in the background via a goroutine would make sure the cache is refreshed regularly.
If the concern is for performance, being able to set a maximum TTL of records in the cache (0 for disabling it) would be great.

@marten-seemann
Copy link
Contributor

If this is done for latency concerns, updating the cache in the background via a goroutine would make sure the cache is refreshed regularly.

How would cache entries ever expire and be garbage collected then?

@thibmeu
Copy link
Contributor Author

thibmeu commented Oct 6, 2021

The code I see would be something like

result, ok := r.getCachedTXT(domain)
if ok {
  go lookupAndUpdateCache(domain)
  return result
}
return lookupAndUpdateCache(domain)

Similar to how gc performed today. If the domain does not resolve, the cache is cleared.

If there needs to be GC, this can be build independently of this feature, as a new issue.

@marten-seemann
Copy link
Contributor

marten-seemann commented Oct 6, 2021

If the domain does not resolve, the cache is cleared.

Domain resolution failures will be very rare. This means that the cache will just keep growing unboundedly as lookups for new domains are performed. This approach seems infeasible to me, unless you build something like an LRU cache.

Depending on the TTL set for the DNS record, this can lead to a significant delay before the resolver returns an up to date DNS record.

Taking a step back, isn't this exactly what the TTL value in the DNS record is there for in the first place?

@thibmeu
Copy link
Contributor Author

thibmeu commented Oct 6, 2021

This means that the cache will just keep growing unboundedly as lookups for new domains are performed

I may misunderstand, but I think this is how the current implementation is designed. I agree it's not ideal, but I think it is beyond the scope of this issue to decide on the best way to purge expired cache entry.

Taking a step back, isn't this exactly what the TTL value in the DNS record is there for in the first place?

Not really. TTL is set by the domain owner. Then it's up to implementations to decide if this TTL suits their needs. Using a custom DoH for instance, the domain records can be updated faster than the set TTL. Quoting RFC2181 Section 8

Implementations are always free to place an upper bound on any TTL received, and treat any larger values as if they were that upper bound. The TTL specifies a maximum time to live, not a mandatory time to live.

@marten-seemann
Copy link
Contributor

I may misunderstand, but I think this is how the current implementation is designed. I agree it's not ideal, but I think it is beyond the scope of this issue to decide on the best way to purge expired cache entry.

I see. Deletion happens only when that record is requested. That's not ideal. There should probably be a GC go routine to clean up expired entries.

TTL is set by the domain owner. Then it's up to implementations to decide if this TTL suits their needs. Using a custom DoH for instance, the domain records can be updated faster than the set TTL. Quoting RFC2181 Section 8

Thanks for referencing the RFC. Your second proposal makes sense to me:

being able to set a maximum TTL of records in the cache (0 for disabling it) would be great.

@vyzo, since you wrote this resolver, what's your opinion on this? Should we add a WithMaximumTTL(time.Duration) option to the constructor?

@vyzo
Copy link
Collaborator

vyzo commented Oct 6, 2021 via email

@aschmahmann aschmahmann added the enhancement New feature or request label Oct 8, 2021
@BigLep BigLep added the help wanted Extra attention is needed label Oct 8, 2021
@aschmahmann
Copy link
Contributor

@thibmeu are you going to be putting up a PR for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants