From e3aed2666a167ed0a9d63d972531027aaa2167e5 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 23 Jun 2016 12:59:54 +0100 Subject: [PATCH] [Fix] Fix round-robin selection when upstreams have no weight --- src/libutil/upstream.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index fe07e89d2..2aa27d929 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -743,6 +743,15 @@ rspamd_upstream_get_round_robin (struct upstream_list *ups, gboolean use_cur) } } + if (max_weight == 0) { + /* + * We actually don't have any weight information, so we could use + * random selection here + */ + selected = g_ptr_array_index (ups->alive, + ottery_rand_range (ups->alive->len - 1)); + } + if (use_cur && selected) { if (selected->cur_weight > 0) { selected->cur_weight--; -- 2.39.5