From: Vsevolod Stakhov Date: Mon, 15 May 2017 10:24:21 +0000 (+0100) Subject: [Fix] Reresolve upstreams even if there is a single server there X-Git-Tag: 1.6.0~208 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=81d002bdfe667692e75845474d781a7aed49e9f6;p=rspamd.git [Fix] Reresolve upstreams even if there is a single server there --- diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index 529d3fcf0..7e64b866c 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -338,23 +338,12 @@ rspamd_upstream_revive_cb (int fd, short what, void *arg) } static void -rspamd_upstream_set_inactive (struct upstream_list *ls, struct upstream *up) +rspamd_upstream_resolve_addrs (const struct upstream_list *ls, + struct upstream *up) { - gdouble ntim; - guint i; - struct upstream *cur; - - RSPAMD_UPSTREAM_LOCK (ls->lock); - g_ptr_array_remove_index (ls->alive, up->active_idx); - up->active_idx = -1; - - /* We need to update all indicies */ - for (i = 0; i < ls->alive->len; i ++) { - cur = g_ptr_array_index (ls->alive, i); - cur->active_idx = i; - } - - if (up->ctx->res != NULL && up->ctx->configured && + if (up->ctx->res != NULL && + up->ctx->configured && + up->dns_requests == 0 && !(ls->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE)) { /* Resolve name of the upstream one more time */ if (up->name[0] != '/') { @@ -374,6 +363,26 @@ rspamd_upstream_set_inactive (struct upstream_list *ls, struct upstream *up) } } } +} + +static void +rspamd_upstream_set_inactive (struct upstream_list *ls, struct upstream *up) +{ + gdouble ntim; + guint i; + struct upstream *cur; + + RSPAMD_UPSTREAM_LOCK (ls->lock); + g_ptr_array_remove_index (ls->alive, up->active_idx); + up->active_idx = -1; + + /* We need to update all indicies */ + for (i = 0; i < ls->alive->len; i ++) { + cur = g_ptr_array_index (ls->alive, i); + cur->active_idx = i; + } + + rspamd_upstream_resolve_addrs (ls, up); REF_RETAIN (up); evtimer_set (&up->ev, rspamd_upstream_revive_cb, up); @@ -421,10 +430,16 @@ rspamd_upstream_fail (struct upstream *up) max_error_rate = 0; } - if (up->ls->ups->len > 1 && error_rate > max_error_rate) { + if (error_rate > max_error_rate) { /* Remove upstream from the active list */ - up->errors = 0; - rspamd_upstream_set_inactive (up->ls, up); + if (up->ls->ups->len > 1) { + up->errors = 0; + rspamd_upstream_set_inactive (up->ls, up); + } + else { + /* Just re-resolve addresses */ + rspamd_upstream_resolve_addrs (up->ls, up); + } } } } @@ -926,34 +941,7 @@ rspamd_upstream_reresolve (struct upstream_ctx *ctx) while (cur) { up = cur->data; REF_RETAIN (up); - - if (up->name[0] != '/' && ctx->res != NULL && - !(up->ls->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE)) { - if (rdns_make_request_full (ctx->res, - rspamd_upstream_dns_cb, - up, - ctx->dns_timeout, - ctx->dns_retransmits, - 1, - up->name, - RDNS_REQUEST_A) != NULL) { - up->dns_requests++; - REF_RETAIN (up); - } - - if (rdns_make_request_full (ctx->res, - rspamd_upstream_dns_cb, - up, - ctx->dns_timeout, - ctx->dns_retransmits, - 1, - up->name, - RDNS_REQUEST_AAAA) != NULL) { - up->dns_requests++; - REF_RETAIN (up); - } - } - + rspamd_upstream_resolve_addrs (up->ls, up); REF_RELEASE (up); cur = g_list_next (cur); }