c-ares
c-ares copied to clipboard
Are open DNS queries still valid after changing the DNS servers?
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?
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.
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?
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.
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?
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.
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?
correct
#191 disallowed this some time ago
The docs did previously mention it would return ARES_ENOTIMP in such a case. But as of PR #594, this is fully supported.