c-ares icon indicating copy to clipboard operation
c-ares copied to clipboard

Are open DNS queries still valid after changing the DNS servers?

Open ChristianAmmer-zz opened this issue 3 years ago • 3 comments

Assume that a communication channel for name service lookups was initialized with ares_init and name lookups were performed by ares_getaddrinfo or ares_gethostbyname, but these lookups are still open (were not answered or timed out).

Is it then possible to change the name servers for the same communication channel (using ares_set_servers) and still get a successful name lookup for the open queries? Or will the name lookups with the previous name servers be canceled?

ChristianAmmer-zz avatar Nov 10 '21 08:11 ChristianAmmer-zz

I'm pretty sure that would be undefined behavior. c-ares doesn't have any way to update the configuration at this time. I know in my own private use of c-ares I keep a list of ares_channel pointers along with an active query count per pointer. All new queries go to the most recent ares_channel in the list, and when the query count hits zero on any pointer that isn't the most recent, I destroy the channel. So when I need to rescan for a config changes, I just create a new channel and make it the most recent in the list.

bradh352 avatar Nov 10 '21 11:11 bradh352

Thank you for the description of how to achieve this goal. Should the effects (when calling ares_set_servers) on the open name lookups be documented?

ChristianAmmer-zz avatar Nov 10 '21 12:11 ChristianAmmer-zz

Probably. I'm not very much in love with the c-ares API in general. Too many public structs, no way to cancel a single query, no way to reload system config on network changes... I'm half-way tempted to create a whole new API and make the old API wrappers around the new.

bradh352 avatar Nov 10 '21 13:11 bradh352

no way to reload system config on network changes.

Does this problem still exist? If the list of DNS servers changes, you need to re-create the channel?

MyLibh avatar Oct 12 '23 19:10 MyLibh

it does still exist, but this might be resolved in the next release as it is on my project list. A lot of the framework to facilitate this was added in the last release.

bradh352 avatar Oct 12 '23 20:10 bradh352

it does still exist, but this might be resolved in the next release as it is on my project list. A lot of the framework to facilitate this was added in the last release.

So, speaking about older versions, when changing the NS list or network type, the channel should be recreated?

MyLibh avatar Oct 13 '23 11:10 MyLibh

correct

bradh352 avatar Oct 13 '23 13:10 bradh352

#191 disallowed this some time ago

dimbleby avatar Oct 22 '23 09:10 dimbleby

The docs did previously mention it would return ARES_ENOTIMP in such a case. But as of PR #594, this is fully supported.

bradh352 avatar Nov 03 '23 23:11 bradh352