From 641e14aa8ff46fc0448f69d409266bba2053ddf4 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 23 Jun 2016 14:15:20 +0100 Subject: [PATCH] [Fix] Fix errors counting in upstreams --- src/libutil/upstream.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index 2aa27d929..e8bf1a19c 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -372,7 +372,7 @@ rspamd_upstream_fail (struct upstream *up) { struct timeval tv; gdouble error_rate, max_error_rate; - gint msec_last, msec_cur; + gdouble sec_last, sec_cur; struct upstream_addr_elt *addr_elt; gettimeofday (&tv, NULL); @@ -384,11 +384,14 @@ rspamd_upstream_fail (struct upstream *up) up->errors = 1; } else if (up->active_idx != -1) { - msec_last = tv_to_msec (&up->tv) / 1000.; - msec_cur = tv_to_msec (&tv) / 1000.; - if (msec_cur >= msec_last) { - if (msec_cur > msec_last) { - error_rate = ((gdouble)up->errors) / (msec_cur - msec_last); + sec_last = tv_to_double (&up->tv); + sec_cur = tv_to_double (&tv); + + if (sec_cur >= sec_last) { + up->errors ++; + + if (sec_cur > sec_last) { + error_rate = ((gdouble)up->errors) / (sec_cur - sec_last); max_error_rate = ((gdouble)up->ctx->max_errors) / up->ctx->error_time; } else { -- 2.39.5