From: Willy Tarreau Date: Wed, 9 Jul 2025 14:20:09 +0000 (+0200) Subject: CLEANUP: stream: lookup server ID using standard functions X-Git-Tag: v3.3-dev4~91 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c8f0b69587649c0f1a6fcb36dc5e0345225deede;p=thirdparty%2Fhaproxy.git CLEANUP: stream: lookup server ID using standard functions The server lookup in sticking_rule_find_target() uses an open-coded tree search while we have a function for this server_find_by_id(). In addition, due to the way it's coded, the stick-table lock also covers the server lookup by accident instead of being released earlier. This is not a real problem though since such feature is rarely used nowadays. Let's clean all this stuff by first retrieving the ID under the lock and then looking up the corresponding server. --- diff --git a/src/stream.c b/src/stream.c index 33d51493b..ef6ae84e4 100644 --- a/src/stream.c +++ b/src/stream.c @@ -1250,10 +1250,10 @@ static inline void sticking_rule_find_target(struct stream *s, struct stktable *t, struct stksess *ts) { struct proxy *px = s->be; - struct eb32_node *node; struct dict_entry *de; void *ptr; struct server *srv; + int id; /* Look for the server name previously stored in stick-table */ HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ts->lock); @@ -1282,13 +1282,13 @@ static inline void sticking_rule_find_target(struct stream *s, /* Look for the server ID */ HA_RWLOCK_RDLOCK(STK_SESS_LOCK, &ts->lock); ptr = __stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_ID); - node = eb32_lookup(&px->conf.used_server_id, stktable_data_cast(ptr, std_t_sint)); + id = stktable_data_cast(ptr, std_t_sint); HA_RWLOCK_RDUNLOCK(STK_SESS_LOCK, &ts->lock); - if (!node) + srv = server_find_by_id(px, id); + if (!srv) return; - srv = container_of(node, struct server, conf.id); found: if ((srv->cur_state != SRV_ST_STOPPED) || (px->options & PR_O_PERSIST) || (s->flags & SF_FORCE_PRST)) {