[6.0] 69d1e52d8 round-robin director to consider all backends also when racing

Reza Naghibi reza at naghibi.com
Tue Apr 20 18:15:06 UTC 2021


commit 69d1e52d87c04b28227c41426d5c8330a05cdee3
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Thu Dec 3 15:15:20 2020 +0100

    round-robin director to consider all backends also when racing
    
    When resolve requests race, we were not guaranteed to consider all
    backends because we updated a shared nxt variable.
    
    Fixes #3474

diff --git a/lib/libvmod_directors/round_robin.c b/lib/libvmod_directors/round_robin.c
index 767fe7258..ac73f9b84 100644
--- a/lib/libvmod_directors/round_robin.c
+++ b/lib/libvmod_directors/round_robin.c
@@ -69,14 +69,16 @@ vmod_rr_resolve(const struct director *dir, struct worker *wrk,
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_ROUND_ROBIN_MAGIC);
 	vdir_rdlock(rr->vd);
+	nxt = rr->nxt;
 	for (u = 0; u < rr->vd->n_backend; u++) {
-		nxt = rr->nxt % rr->vd->n_backend;
-		rr->nxt = nxt + 1;
 		be = rr->vd->backend[nxt];
+		nxt++;
+		nxt %= rr->vd->n_backend;
 		CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
 		if (be->healthy(be, bo, NULL))
 			break;
 	}
+	rr->nxt = nxt;
 	vdir_unlock(rr->vd);
 	if (u == rr->vd->n_backend)
 		be = NULL;


More information about the varnish-commit mailing list