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.
This commit is contained in:
Willy Tarreau 2025-07-09 16:20:09 +02:00
parent a3443db2eb
commit c8f0b69587

View 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)) {