From 89648ee8c27f91b178c6eda3dadec854bd631cb9 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Wed, 13 Jan 2010 14:13:14 -0500 Subject: Explicitly set async DNS timeout We will allow 5s per DNS server, no retries. --- server/resolv/async_resolv.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'server/resolv/async_resolv.c') diff --git a/server/resolv/async_resolv.c b/server/resolv/async_resolv.c index c350d6c36..8455b575e 100644 --- a/server/resolv/async_resolv.c +++ b/server/resolv/async_resolv.c @@ -72,6 +72,9 @@ struct resolv_ctx { ares_channel channel; /* List of file descriptors that are watched by tevent. */ struct fd_watch *fds; + + /* Time in milliseconds before canceling a DNS request */ + int timeout; }; struct resolv_ctx *context_list; @@ -242,7 +245,12 @@ recreate_ares_channel(struct resolv_ctx *ctx) */ options.sock_state_cb = fd_event; options.sock_state_cb_data = ctx; - ret = ares_init_options(&new_channel, &options, ARES_OPT_SOCK_STATE_CB); + options.timeout = ctx->timeout * 1000; + options.tries = 1; + ret = ares_init_options(&new_channel, &options, + ARES_OPT_SOCK_STATE_CB | + ARES_OPT_TIMEOUTMS | + ARES_OPT_TRIES); if (ret != ARES_SUCCESS) { DEBUG(1, ("Failed to initialize ares channel: %s\n", resolv_strerror(ret))); @@ -261,7 +269,7 @@ recreate_ares_channel(struct resolv_ctx *ctx) int resolv_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx, - struct resolv_ctx **ctxp) + int timeout, struct resolv_ctx **ctxp) { int ret; struct resolv_ctx *ctx; @@ -271,6 +279,7 @@ resolv_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx, return ENOMEM; ctx->ev_ctx = ev_ctx; + ctx->timeout = timeout; ret = recreate_ares_channel(ctx); if (ret != EOK) { -- cgit