]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: connection: fix loop iter on connection takeover
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 14 Oct 2020 16:17:03 +0000 (18:17 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 15 Oct 2020 13:19:25 +0000 (15:19 +0200)
The loop always missed one iteration due to the incrementation done on
the for check. Move the incrementation on the loop last statement to fix
this behaviour.

This bug has a very limited impact, not at all visible to the user, but
could be backported to 2.2.

src/backend.c

index 490dc1f2823801f533529b5ee801399afd202464..19bce9c198109e4609e1f57c49be0d325f7a030e 100644 (file)
@@ -1154,7 +1154,8 @@ static struct connection *conn_backend_get(struct server *srv, int is_safe)
        if (stop >= global.nbthread)
                stop = 0;
 
-       for (i = stop; !found && (i = ((i + 1 == global.nbthread) ? 0 : i + 1)) != stop;) {
+       i = stop;
+       do {
                struct mt_list *elt1, elt2;
 
                if (!srv->curr_idle_thr[i] || i == tid)
@@ -1183,7 +1184,7 @@ static struct connection *conn_backend_get(struct server *srv, int is_safe)
                        }
                }
                HA_SPIN_UNLOCK(OTHER_LOCK, &idle_conns[i].takeover_lock);
-       }
+       } while (!found && (i = (i + 1 == global.nbthread) ? 0 : i + 1) != stop);
 
        if (!found)
                conn = NULL;