From: Olivier Houchard Date: Wed, 2 Apr 2025 10:40:42 +0000 (+0000) Subject: BUG/MEDIUM: leastconn: Don't try to reposition if the server is down X-Git-Tag: v3.2-dev9~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f59297e49250402650088c89e7c79a1d5291b6ac;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: leastconn: Don't try to reposition if the server is down 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.  --- diff --git a/src/lb_fwlc.c b/src/lb_fwlc.c index c647336c5..354e03d17 100644 --- a/src/lb_fwlc.c +++ b/src/lb_fwlc.c @@ -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.