Skip to content

Commit

Permalink
Resolver: retry sending queries on errors (ticket #1511).
Browse files Browse the repository at this point in the history
Errors when sending UDP datagrams can happen, e.g., when local IP address
changes (see fa0e093b64d7), or an unavailable DNS server on the LAN can cause
send() to fail with EHOSTDOWN on BSD systems.  If this happens during
initial query, retry sending immediately, to a different DNS server when
possible.  If this is not enough, allow normal resend to happen by ignoring
the return code of the second ngx_resolver_send_query() call, much like we
do in ngx_resolver_resend().
  • Loading branch information
mdounin committed Jul 5, 2018
1 parent f206a11 commit f62d460
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/core/ngx_resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,15 @@ ngx_resolve_name_locked(ngx_resolver_t *r, ngx_resolver_ctx_t *ctx,
rn->nsrvs = 0;

if (ngx_resolver_send_query(r, rn) != NGX_OK) {
goto failed;

/* immediately retry once on failure */

rn->last_connection++;
if (rn->last_connection == r->connections.nelts) {
rn->last_connection = 0;
}

(void) ngx_resolver_send_query(r, rn);
}

if (ngx_resolver_set_timeout(r, ctx) != NGX_OK) {
Expand Down Expand Up @@ -1051,7 +1059,15 @@ ngx_resolve_addr(ngx_resolver_ctx_t *ctx)
rn->nsrvs = 0;

if (ngx_resolver_send_query(r, rn) != NGX_OK) {
goto failed;

/* immediately retry once on failure */

rn->last_connection++;
if (rn->last_connection == r->connections.nelts) {
rn->last_connection = 0;
}

(void) ngx_resolver_send_query(r, rn);
}

if (ngx_resolver_set_timeout(r, ctx) != NGX_OK) {
Expand Down

0 comments on commit f62d460

Please sign in to comment.