Add c-ares support for DNS resolution with timeout#323
Open
bjosv wants to merge 3 commits into
Open
Conversation
Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
When built with USE_CARES=1 (make) or -DENABLE_CARES=ON (CMake), DNS resolution in the sync API uses c-ares with a poll loop bounded by connect_timeout (defaulting to 5s). This prevents indefinite hangs when DNS is slow or unresponsive. The c-ares path uses ARES_OPT_SOCK_STATE_CB for fd tracking, and a short-lived channel per resolve call. IPv4/IPv6 fallback behavior is preserved. Without enabling c-ares, behavior is unchanged (plain getaddrinfo). Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
getaddrinfo()has no timeout mechanism. When DNS is slow or unresponsive, libvalkey hangs indefinitely with no way to cancel the lookup.This PR adds optional c-ares integration (
USE_CARES=1/-DENABLE_CARES=ON) that replacesgetaddrinfo()with c-ares driven by apoll()loop. DNS resolution respectsconnect_timeout(defaulting to 5 seconds if unset), so lookups that previously hung indefinitely now fail with a timeout error.The PR consists of two commits: the first moves existing DNS logic into
dns.[ch], and the second adds the c-ares integration.Notes:
Add non-blocking DNS for the async API via c-ares event-loop integration #324
will make DNS fully non-blocking for the async API via event-loop integration.
getaddrinfo)::1) are detected and handled correctlyTesting:
ut_dns_caresunit test covering IP literals, hostnames, non-existent hosts, IPv6, and timeoutut_connect_fallbackdisabled when c-ares is enabled (it overridesgetaddrinfowhich c-ares bypasses)