diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-10-31 17:35:02 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-10-31 17:35:02 +0000 |
commit | ab2d0a0b1c89d22e970a7ddef3675d462ebb6b17 (patch) | |
tree | 101e56ff5146bf46925397a2fa2a9547561b9c6c /src/libutil/upstream.c | |
parent | e3057e5e4623e9075602b2c4c20346c8479510fe (diff) | |
download | rspamd-ab2d0a0b1c89d22e970a7ddef3675d462ebb6b17.tar.gz rspamd-ab2d0a0b1c89d22e970a7ddef3675d462ebb6b17.zip |
[Fix] Fix upstreams exclusion logic
Diffstat (limited to 'src/libutil/upstream.c')
-rw-r--r-- | src/libutil/upstream.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index cef508e4d..83da7a3e5 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -726,7 +726,7 @@ rspamd_upstream_set_inactive (struct upstream_list *ls, struct upstream *upstrea void rspamd_upstream_fail (struct upstream *up, gboolean addr_failure) { - gdouble error_rate, max_error_rate; + gdouble error_rate = 0, max_error_rate = 0; gdouble sec_last, sec_cur; struct upstream_addr_elt *addr_elt; struct upstream_list_watcher *w; @@ -752,21 +752,18 @@ rspamd_upstream_fail (struct upstream *up, gboolean addr_failure) if (sec_cur >= sec_last) { up->errors ++; + DL_FOREACH (up->ls->watchers, w) { if (w->events_mask & RSPAMD_UPSTREAM_WATCH_FAILURE) { w->func (up, RSPAMD_UPSTREAM_WATCH_FAILURE, up->errors, w->ud); } } - if (sec_cur > sec_last) { + if (sec_cur - sec_last >= up->ls->limits.error_time) { error_rate = ((gdouble)up->errors) / (sec_cur - sec_last); max_error_rate = ((gdouble)up->ls->limits.max_errors) / up->ls->limits.error_time; } - else { - error_rate = 1; - max_error_rate = 0; - } if (error_rate > max_error_rate) { /* Remove upstream from the active list */ @@ -782,6 +779,11 @@ rspamd_upstream_fail (struct upstream *up, gboolean addr_failure) } } } + else if (sec_cur - sec_last >= up->ls->limits.error_time) { + /* Forget the whole interval */ + up->last_fail = sec_cur; + up->errors = 1; + } } } |