[GH-ISSUE #2214] DNS Resolver rotate feature #923

Open
opened 2026-03-16 00:58:38 +03:00 by kerem · 9 comments
Owner

Originally created by @TSDevHub on GitHub (May 17, 2024).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2214

Is your feature request related to a problem? Please describe.
Hello, I want to DNS cache a query which yields multiple A records and rotate through the A records.

I know you guys have https://docs.rs/hickory-resolver/0.24.1/hickory_resolver/config/struct.ResolverOpts.html#structfield.rotate feature, but upon inspecting your resolver source code, doesn't seem hickory resolver use it to rotate between cached A records for a given query, which would be useful for ip load balancing for services that use round-robin DNS. I also verified that with this rotate flag on, hickory resolver do not rotate between cached records, so if I am DNS caching, it just uses the same record even though in the IRU cache, hickory stores all the records for the query. This could be bad for overloading that particular ip.

Having the rotate feature work would make hickory resolver more adoptable for users trying to call service domain endpoint which use round-robin DNS for load balancing. Also might prevent users who enabled hickory resolver caching from unexpectedly bringing down their destination service hosts, due to surge in load in one ip due to caching.

Describe the solution you'd like
Allow hickory resolver to honor the rotate option, and round-robin rotate cached DNS query records.

Suppose we made DNS query for domain www.myservice.com and it came up with these A records

1.2.3.4 IN A www.myservice.com
5.6.7.8 IN A www.myservice.com
9.10.11.12 IN A www.myservice.com

rotate would alternate fetching A records from DNS cache like so 1.2.3.4 -> 5.6.7.8 -> 9.10.11.12 -> back to -> 1.2.3.4 -> 5.6.7.8 -> so on, in round robin fashion, as long as cache is not expired

Also, would appreciate update in doc that this rotate flag currently is not implemented as it was misleading.

Describe alternatives you've considered
not use caching by fixing size = 0 for ip balancing, but.. not performant

Additional context
none

Originally created by @TSDevHub on GitHub (May 17, 2024). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2214 **Is your feature request related to a problem? Please describe.** Hello, I want to DNS cache a query which yields multiple A records and rotate through the A records. I know you guys have https://docs.rs/hickory-resolver/0.24.1/hickory_resolver/config/struct.ResolverOpts.html#structfield.rotate feature, but upon inspecting your resolver source code, doesn't seem hickory resolver use it to rotate between cached A records for a given query, which would be useful for ip load balancing for services that use round-robin DNS. I also verified that with this rotate flag on, hickory resolver do not rotate between cached records, so if I am DNS caching, it just uses the same record even though in the IRU cache, hickory stores all the records for the query. This could be bad for overloading that particular ip. Having the rotate feature work would make hickory resolver more adoptable for users trying to call service domain endpoint which use round-robin DNS for load balancing. Also might prevent users who enabled hickory resolver caching from unexpectedly bringing down their destination service hosts, due to surge in load in one ip due to caching. **Describe the solution you'd like** Allow hickory resolver to honor the rotate option, and round-robin rotate cached DNS query records. Suppose we made DNS query for domain www.myservice.com and it came up with these A records ``` 1.2.3.4 IN A www.myservice.com 5.6.7.8 IN A www.myservice.com 9.10.11.12 IN A www.myservice.com ``` rotate would alternate fetching A records from DNS cache like so `1.2.3.4` -> `5.6.7.8` -> `9.10.11.12` -> back to -> `1.2.3.4` -> `5.6.7.8` -> so on, in round robin fashion, as long as cache is not expired Also, would appreciate update in doc that this rotate flag currently is not implemented as it was misleading. **Describe alternatives you've considered** not use caching by fixing size = 0 for ip balancing, but.. not performant **Additional context** none
Author
Owner

@bluejekyll commented on GitHub (May 18, 2024):

yes, this would be a nice feature to add. I think it's also related to #1924, as this could be used in the forwarding hickory-dns server.

To make this accurate it would probably mean recording some stats on each RRSet and it's use in the cache, which I don't think we do today. That said, I think randomizing the order of the addresses is also something that the calling code can do. I've always been a little uncomfortable with changing RRSets from what was returned upstream, but I'm not a purest on this.

If you wanted to post something up, maybe even keeping it simple for now by just randomizing the order of the records in the result from the cache, that would be interesting to see.

<!-- gh-comment-id:2118983966 --> @bluejekyll commented on GitHub (May 18, 2024): yes, this would be a nice feature to add. I think it's also related to #1924, as this could be used in the forwarding hickory-dns server. To make this accurate it would probably mean recording some stats on each RRSet and it's use in the cache, which I don't think we do today. That said, I think randomizing the order of the addresses is also something that the calling code can do. I've always been a little uncomfortable with changing RRSets from what was returned upstream, but I'm not a purest on this. If you wanted to post something up, maybe even keeping it simple for now by just randomizing the order of the records in the result from the cache, that would be interesting to see.
Author
Owner

@TSDevHub commented on GitHub (May 18, 2024):

Hey Benjamin, thanks for your reply :)

Ah I didn't know hickory also provided DNS server capability, I was just using it as a resolver to call DNS server.

I think having a feature where you select a random record in the DNS cache if cache item has multiple records sounds like a great start. Perhaps hickory-resolver users would find that this is good enough for their use-case with short enough TTL. And later we can add round robin.

I am new to this repo and wonder how features are prioritized and released, what is next?

<!-- gh-comment-id:2119018077 --> @TSDevHub commented on GitHub (May 18, 2024): Hey Benjamin, thanks for your reply :) Ah I didn't know hickory also provided DNS server capability, I was just using it as a resolver to call DNS server. I think having a feature where you select a random record in the DNS cache if cache item has multiple records sounds like a great start. Perhaps hickory-resolver users would find that this is good enough for their use-case with short enough TTL. And later we can add round robin. I am new to this repo and wonder how features are prioritized and released, what is next?
Author
Owner

@bluejekyll commented on GitHub (May 18, 2024):

we basically include things as they're ready and then publish in the next release. We're working on a new 0.25 release that will probably come once we have all of the related crates that use ring and rustls updated. So that will come as soon as some of our dependencies are updated.

<!-- gh-comment-id:2119019319 --> @bluejekyll commented on GitHub (May 18, 2024): we basically include things as they're ready and then publish in the next release. We're working on a new `0.25` release that will probably come once we have all of the related crates that use `ring` and `rustls` updated. So that will come as soon as some of our dependencies are updated.
Author
Owner

@bluejekyll commented on GitHub (May 18, 2024):

Something to consider when implementing this, perhaps it could be included only in the RRSet returned by the lookup function... i.e. that way it would make it something like lookup_ip(...).await?.randomized().next()

<!-- gh-comment-id:2119019932 --> @bluejekyll commented on GitHub (May 18, 2024): Something to consider when implementing this, perhaps it could be included only in the RRSet returned by the lookup function... i.e. that way it would make it something like `lookup_ip(...).await?.randomized().next()`
Author
Owner

@TSDevHub commented on GitHub (May 19, 2024):

I see, then I will keep an eye on this feature request. Thanks again!

<!-- gh-comment-id:2119069254 --> @TSDevHub commented on GitHub (May 19, 2024): I see, then I will keep an eye on this feature request. Thanks again!
Author
Owner

@Xuanwo commented on GitHub (Sep 11, 2024):

Hi, @TSDevHub, are you working on this now? I recently found that I need this feature and would be happy to collaborate on it.

<!-- gh-comment-id:2342707393 --> @Xuanwo commented on GitHub (Sep 11, 2024): Hi, @TSDevHub, are you working on this now? I recently found that I need this feature and would be happy to collaborate on it.
Author
Owner

@TSDevHub commented on GitHub (Sep 11, 2024):

Hey @Xuanwo, I am currently not working on this and been waiting for the 0.25 release so it can picked up after. Good to see that more people want this feature :)

As for collaboration, I am uncertain if I would be able to collaborate with you at the moment so if you want to work on it now, please feel free to start

<!-- gh-comment-id:2344134418 --> @TSDevHub commented on GitHub (Sep 11, 2024): Hey @Xuanwo, I am currently not working on this and been waiting for the `0.25` release so it can picked up after. Good to see that more people want this feature :) As for collaboration, I am uncertain if I would be able to collaborate with you at the moment so if you want to work on it now, please feel free to start
Author
Owner

@aajtodd commented on GitHub (Mar 7, 2025):

What is the intent of the rotate resolver option? Is it meant to work as described in this issue (i.e. if there are multiple cached entries, rotate through them on each invocation)? Looking at the code it doesn't seem to do much today, so I'm curious the original intent and what purpose it serves right now.

<!-- gh-comment-id:2706507768 --> @aajtodd commented on GitHub (Mar 7, 2025): What is the intent of the [rotate](https://docs.rs/hickory-resolver/latest/hickory_resolver/config/struct.ResolverOpts.html#structfield.rotate) resolver option? Is it meant to work as described in this issue (i.e. if there are multiple cached entries, rotate through them on each invocation)? Looking at the code it doesn't seem to do much today, so I'm curious the original intent and what purpose it serves right now.
Author
Owner

@djc commented on GitHub (Mar 11, 2025):

I submitted #2841 to remove the rotate option for now, since, as you mentioned, it doesn't do anything today. Happy to review changes that bring back similar functionality.

<!-- gh-comment-id:2714102406 --> @djc commented on GitHub (Mar 11, 2025): I submitted #2841 to remove the `rotate` option for now, since, as you mentioned, it doesn't do anything today. Happy to review changes that bring back similar functionality.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#923
No description provided.