feat: only cache final target record when dns sever response #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
The current DNS resolving and caching logic operates at the RR (Resource Record) level.
Each record in a CNAME chain (CNAME / A / AAAA) is cached independently with its own TTL.
In real-world deployments, this behavior can lead to inconsistencies:
For gateway and traffic-routing components, this behavior can be undesirable.
Practical Limitation of Intermediate Records
In addition to TTL consistency, there is a practical operational constraint:
In multi-region, multi-cloud, or third-party DNS environments (e.g. CDN or cloud-internal domains):
This can cause traffic to be routed based on a DNS chain that is no longer valid from the resolver’s perspective.
Example
Possible issue:
one.cloudfront.net expires or becomes unreachable in a given region
What’s Changed
This PR introduces an optional configuration flag:
When finalCacheOnly is enabled:
The resolver only caches the final A / AAAA record
The cache TTL is calculated as the minimum TTL across the entire CNAME chain
Intermediate CNAME records are not cached or reused independently