-
-
Notifications
You must be signed in to change notification settings - Fork 910
[client] Implement DNS query caching in DNSForwarder #4574
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements DNS query caching in the DNSForwarder to improve performance and provide fallback responses when upstream DNS servers fail. The cache stores successful DNS query results and serves them when upstream resolution fails.
- Added a new cache component to store DNS query results by domain and query type
- Integrated cache storage after successful DNS resolutions
- Enhanced error handling to serve cached responses as fallback when upstream DNS fails
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| client/internal/dnsfwd/cache.go | New cache implementation with thread-safe operations for storing and retrieving DNS records |
| client/internal/dnsfwd/forwarder.go | Integrated cache into DNSForwarder and enhanced error handling to use cached responses as fallback |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Currently the cache is unbounded and there is no way to manually clear it, can we do something about it?
- NXDOMAIN is not cached, but it should be
UpdateDomainsmight remove some domains in which case we should remove those from the cache as well
|
|
@lixmal added cache for NXDOMAIN, also added a method to remove stale cache entries on UpdateDomains. Regarding to the clearing cache, maybe we can expire not used cache items after some time but i think it can be implemented later /cc @mlsmaycon |
|
Thanks for implementing that, can help quite a lot.
Again thanks for implementing this fallback. |



Describe your changes
[client] Implement DNS query caching in DNSForwarder
Issue ticket number and link
Stack
Checklist
Documentation
Select exactly one:
.
Docs PR URL (required if "docs added" is checked)
Paste the PR link from https://github.com/netbirdio/docs here:
https://github.com/netbirdio/docs/pull/__