Add flag to not use a default local named server on channel initialization - #713
Conversation
a channel and no other servers are available. This can be used in scenarios where an application will never have access to a local named server, and it is preferred to fail initialization rather than wait for a DNS query to later fail.
|
Makes sense, however I wonder if we shouldn't use this same error code if someone calls ares_set_servers*() with an empty server list then tries to perform a query. No need for it to be init-only. (Unfortunately, we have to support the ability to completely clear the server list due to some odd NodeJS requirement). |
gets raised whenever a query is performed and fails due to no servers being available.
Thank you, making the error a little more generic sounds good to me. We check for no servers in 2 places during queries. I think updating these to use the new error would make sense.
I have pushed a markup to the PR which does this. It also renames the error to An alternative could be to reuse |
Hello, I work on an application for Microsoft which uses c-ares to perform DNS lookups. We have made some minor changes to the library over time, and would like to contribute these back to the project in case they are useful more widely. This PR adds a new channel init flag, described below.
Please let me know if I can include any more information to make this PR better/easier for you to review. Thanks!
Summary
When initializing a channel with
ares_init_options(), if there are no nameservers available (becauseARES_OPT_SERVERSis not used and/etc/resolv.confis either empty or not available) then a default local named server will be added to the channel.However in some applications a local named server will never be available. In this case, all subsequent queries on the channel will fail.
If we know this ahead of time, then it may be preferred to fail channel initialization directly rather than wait for the queries to fail. This gives better visibility, since we know that the failure is due to missing servers rather than something going wrong with the queries.
This PR adds a new flag
ARES_FLAG_NO_DFLT_SVR, to indicate that a default local named server should not be added to a channel in this scenario. Instead, a new errorARES_EINITNOSERVERis returned and initialization fails.Testing
I have added 2 new FV tests:
ContainerNoDfltSvrEmptyInitto test that initialization fails when no nameservers are available and the flag is set.ContainerNoDfltSvrFullInitto test that initialization still succeeds when the flag is set but other nameservers are available.Existing FVs are all passing.
Documentation
I have had a go at manually updating the docs to describe the new flag/error, but couldn't see any contributing guidance about testing this. Please let me know if you'd like anything more here.