]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: leastconn: Don't try to reposition if the server is down
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 2 Apr 2025 10:40:42 +0000 (10:40 +0000)
committerOlivier Houchard <cognet@ci0.org>
Wed, 2 Apr 2025 10:24:04 +0000 (12:24 +0200)
It may happen that the server is going down, and fwlc_srv_reposition()
is still called, because streams still attached to the server are
being terminated.
So in fwlc_srv_reposition(), just do nothing if we've been removed from
the tree.

This should fix github issue #2919.

This should not be backported, unless commit
9fe72bba3cf3484577fa1ef00723de08df757996 is also backported.


src/lb_fwlc.c

index c647336c538466e8f59b4b12ff98790bac00846b..354e03d17add03a5810f5f0a115e5dea8e21085e 100644 (file)
@@ -330,6 +330,15 @@ static void fwlc_srv_reposition(struct server *s)
                return;
        }
 
+       /*
+        * We're not in the tree, the server is probably down, don't
+        * do anything.
+        */
+       if (unlikely(!s->tree_elt)) {
+               HA_RWLOCK_RDUNLOCK(LBPRM_LOCK, &s->proxy->lbprm.lock);
+               _HA_ATOMIC_STORE(&s->lb_lock, 0);
+               return;
+       }
        node = eb32_lookup(s->lb_tree, new_key);
        if (node)
                tree_elt = container_of(node, struct fwlc_tree_elt, lb_node);
@@ -462,8 +471,7 @@ static void fwlc_srv_reposition(struct server *s)
 
        __ha_barrier_store();
 
-       if (s->tree_elt)
-                _HA_ATOMIC_DEC(&s->tree_elt->elements);
+       _HA_ATOMIC_DEC(&s->tree_elt->elements);
 
        /*
         * Now lock the existing element, and its target list.