]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: stream: lookup server ID using standard functions
authorWilly Tarreau <w@1wt.eu>
Wed, 9 Jul 2025 14:20:09 +0000 (16:20 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 15 Jul 2025 08:30:28 +0000 (10:30 +0200)
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.

src/stream.c

index 33d51493b83b10a26cee1774a3835e22743a758d..ef6ae84e4efd2c151f2451fa26dc8c3f031cc79d 100644 (file)
@@ -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 <t> 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)) {