]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: pass the thread number to conn_delete_from_tree()
authorWilly Tarreau <w@1wt.eu>
Fri, 12 Sep 2025 14:47:12 +0000 (16:47 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 16 Sep 2025 07:23:46 +0000 (09:23 +0200)
We'll soon need to choose the server's root based on the connection's
flags, and for this we'll need the thread it's attached to, which is
not always the current one. This patch simply passes the thread number
from all callers. They know it because they just set the idle_conns
lock on it prior to calling the function.

include/haproxy/connection.h
src/backend.c
src/connection.c
src/mux_fcgi.c
src/mux_h1.c
src/mux_h2.c
src/mux_quic.c
src/mux_spop.c
src/server.c
src/ssl_sock.c

index d759238b2a9d177355e28c6295a8d69d66d14458..d796991b449fde3431e8744402a4e45a7b9bd3ca 100644 (file)
@@ -84,7 +84,7 @@ int conn_install_mux_be(struct connection *conn, void *ctx, struct session *sess
                         const struct mux_ops *force_mux_ops);
 int conn_install_mux_chk(struct connection *conn, void *ctx, struct session *sess);
 
-void conn_delete_from_tree(struct connection *conn);
+void conn_delete_from_tree(struct connection *conn, int thr);
 
 void conn_init(struct connection *conn, void *target);
 struct connection *conn_new(void *target);
index a835be5a12797794c6fa34b6ce7b7055fa4122bc..ea3440c37db648461d5998c776cada93e3c86e5c 100644 (file)
@@ -1313,7 +1313,7 @@ struct connection *conn_backend_get(int reuse_mode,
        HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
        conn = srv_lookup_conn(is_safe ? &srv->per_thr[tid].safe_conns : &srv->per_thr[tid].idle_conns, hash);
        if (conn)
-               conn_delete_from_tree(conn);
+               conn_delete_from_tree(conn, tid);
 
        /* If we failed to pick a connection from the idle list, let's try again with
         * the safe list.
@@ -1321,7 +1321,7 @@ struct connection *conn_backend_get(int reuse_mode,
        if (!conn && !is_safe && srv->curr_safe_nb > 0) {
                conn = srv_lookup_conn(&srv->per_thr[tid].safe_conns, hash);
                if (conn) {
-                       conn_delete_from_tree(conn);
+                       conn_delete_from_tree(conn, tid);
                        is_safe = 1;
                }
        }
@@ -1382,7 +1382,7 @@ check_tgid:
                        conn = srv_lookup_conn(tree, hash);
                        while (conn) {
                                if (conn->mux->takeover && conn->mux->takeover(conn, i, 0) == 0) {
-                                       conn_delete_from_tree(conn);
+                                       conn_delete_from_tree(conn, i);
                                        _HA_ATOMIC_INC(&activity[tid].fd_takeover);
                                        found = 1;
                                        break;
@@ -1487,7 +1487,7 @@ takeover_random_idle_conn(struct eb_root *root, int curtid)
                hash_node = eb64_entry(node, struct conn_hash_node, node);
                conn = hash_node->conn;
                if (conn && conn->mux->takeover && conn->mux->takeover(conn, curtid, 1) == 0) {
-                       conn_delete_from_tree(conn);
+                       conn_delete_from_tree(conn, curtid);
                        return conn;
                }
                node = eb64_next(node);
@@ -1744,7 +1744,7 @@ int be_reuse_connection(int64_t hash, struct session *sess,
                        if (avail <= 1) {
                                /* no more streams available, remove it from the list */
                                HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
-                               conn_delete_from_tree(srv_conn);
+                               conn_delete_from_tree(srv_conn, tid);
                                HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
                        }
 
@@ -1852,7 +1852,7 @@ int connect_server(struct stream *s)
                HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
                if (!LIST_ISEMPTY(&srv->per_thr[tid].idle_conn_list)) {
                        tokill_conn = LIST_ELEM(srv->per_thr[tid].idle_conn_list.n, struct connection *, idle_list);
-                       conn_delete_from_tree(tokill_conn);
+                       conn_delete_from_tree(tokill_conn, tid);
                        HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
 
                        /* Release the idle lock before calling mux->destroy.
@@ -1881,7 +1881,7 @@ int connect_server(struct stream *s)
 
                                if (!LIST_ISEMPTY(&srv->per_thr[i].idle_conn_list)) {
                                        tokill_conn = LIST_ELEM(srv->per_thr[i].idle_conn_list.n, struct connection *, idle_list);
-                                       conn_delete_from_tree(tokill_conn);
+                                       conn_delete_from_tree(tokill_conn, i);
                                }
                                HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[i].idle_conns_lock);
 
index 39e2eb3c838006bd47ad355221019ceba116c417..896dbc1a74f422d0ee47c1762f0ebef0d8bfd3ce 100644 (file)
@@ -73,12 +73,13 @@ struct conn_tlv_list *conn_get_tlv(struct connection *conn, int type)
        return NULL;
 }
 
-/* Remove <conn> idle connection from its attached tree (idle, safe or avail).
- * If also present in the secondary server idle list, conn is removed from it.
+/* Remove <conn> idle connection from its attached tree (idle, safe or avail)
+ * for the server in the connection's target and thread <thr>. If also present
+ * in the secondary server idle list, conn is removed from it.
  *
  * Must be called with idle_conns_lock held.
  */
-void conn_delete_from_tree(struct connection *conn)
+void conn_delete_from_tree(struct connection *conn, int thr)
 {
        LIST_DEL_INIT(&conn->idle_list);
        eb64_delete(&conn->hash_node->node);
@@ -209,7 +210,7 @@ int conn_notify_mux(struct connection *conn, int old_flags, int forced_wake)
                                        conn_in_list = 0;
                        }
                        else {
-                               conn_delete_from_tree(conn);
+                               conn_delete_from_tree(conn, tid);
                        }
                        HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
                }
index caac5450d512009a45f3d04d9815247375b1e3cf..fc714d5a88d68accc3cf825a4e7a032a4fd2cdfd 100644 (file)
@@ -3068,7 +3068,7 @@ struct task *fcgi_io_cb(struct task *t, void *ctx, unsigned int state)
                                        conn_in_list = 0;
                        }
                        else {
-                               conn_delete_from_tree(conn);
+                               conn_delete_from_tree(conn, tid);
                        }
                }
 
@@ -3329,7 +3329,7 @@ struct task *fcgi_timeout_task(struct task *t, void *context, unsigned int state
                 * to steal it from us.
                 */
                if (fconn->conn->flags & CO_FL_LIST_MASK)
-                       conn_delete_from_tree(fconn->conn);
+                       conn_delete_from_tree(fconn->conn, tid);
                else if (fconn->conn->flags & CO_FL_SESS_IDLE)
                        session_detach_idle_conn(fconn->conn->owner, fconn->conn);
 
index d68582a9726cb14340af33652d46d15e866e42bf..234c26741210c9fb0bf6097812e7fb87f3e3a91a 100644 (file)
@@ -4311,7 +4311,7 @@ struct task *h1_io_cb(struct task *t, void *ctx, unsigned int state)
                                        conn_in_list = 0;
                        }
                        else {
-                               conn_delete_from_tree(conn);
+                               conn_delete_from_tree(conn, tid);
                        }
                }
 
@@ -4451,7 +4451,7 @@ struct task *h1_timeout_task(struct task *t, void *context, unsigned int state)
                 * to steal it from us.
                 */
                if (h1c->conn->flags & CO_FL_LIST_MASK)
-                       conn_delete_from_tree(h1c->conn);
+                       conn_delete_from_tree(h1c->conn, tid);
 
                HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
 
index a64e432dc7d563b1c643c103b4a34d1edbf723c8..309e06e63ead7ee073d45df4cbf1f0a2a8f7386c 100644 (file)
@@ -4966,7 +4966,7 @@ struct task *h2_io_cb(struct task *t, void *ctx, unsigned int state)
                                        conn_in_list = 0;
                        }
                        else {
-                               conn_delete_from_tree(conn);
+                               conn_delete_from_tree(conn, tid);
                        }
                }
 
@@ -5143,7 +5143,7 @@ static int h2_process(struct h2c *h2c)
                /* connections in error must be removed from the idle lists */
                if (conn->flags & CO_FL_LIST_MASK) {
                        HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
-                       conn_delete_from_tree(conn);
+                       conn_delete_from_tree(conn, tid);
                        HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
                }
        }
@@ -5151,7 +5151,7 @@ static int h2_process(struct h2c *h2c)
                /* connections in error must be removed from the idle lists */
                if (conn->flags & CO_FL_LIST_MASK) {
                        HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
-                       conn_delete_from_tree(conn);
+                       conn_delete_from_tree(conn, tid);
                        HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
                }
        }
@@ -5259,7 +5259,7 @@ struct task *h2_timeout_task(struct task *t, void *context, unsigned int state)
                 * to steal it from us.
                 */
                if (h2c->conn->flags & CO_FL_LIST_MASK)
-                       conn_delete_from_tree(h2c->conn);
+                       conn_delete_from_tree(h2c->conn, tid);
                else if (h2c->conn->flags & CO_FL_SESS_IDLE)
                        session_detach_idle_conn(h2c->conn->owner, h2c->conn);
 
@@ -5341,7 +5341,7 @@ do_leave:
        /* in any case this connection must not be considered idle anymore */
        if (h2c->conn->flags & CO_FL_LIST_MASK) {
                HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
-               conn_delete_from_tree(h2c->conn);
+               conn_delete_from_tree(h2c->conn, tid);
                HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
        }
 
index 1dd01534b6f7047e1d5db65dee63c1cb3a1bace4..e51c99fb6bf4874d493beaaa1f0b5b6d33d14eb7 100644 (file)
@@ -3205,7 +3205,7 @@ static void qcc_shutdown(struct qcc *qcc)
 
        /* A connection is not reusable if app layer is closed. */
        if (qcc->flags & QC_CF_IS_BACK)
-               conn_delete_from_tree(qcc->conn);
+               conn_delete_from_tree(qcc->conn, tid);
 
  out:
        qcc->app_st = QCC_APP_ST_SHUT;
@@ -3408,7 +3408,7 @@ struct task *qcc_io_cb(struct task *t, void *ctx, unsigned int state)
                        if (conn->flags & CO_FL_SESS_IDLE)
                                session_detach_idle_conn(conn->owner, conn);
                        else
-                               conn_delete_from_tree(conn);
+                               conn_delete_from_tree(conn, tid);
                }
 
                HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
@@ -3532,7 +3532,7 @@ static struct task *qcc_timeout_task(struct task *t, void *ctx, unsigned int sta
                 * attempts to steal it from us.
                 */
                if (qcc->conn->flags & CO_FL_LIST_MASK)
-                       conn_delete_from_tree(qcc->conn);
+                       conn_delete_from_tree(qcc->conn, tid);
                else if (qcc->conn->flags & CO_FL_SESS_IDLE)
                        session_unown_conn(qcc->conn->owner, qcc->conn);
 
index b1cb2676c72208af036a335f02d4d1cf7f0d3e1f..2583b3c9eb4d94d8c7f1d1748ff00bc15f517ad0 100644 (file)
@@ -2564,7 +2564,7 @@ static struct task *spop_io_cb(struct task *t, void *ctx, unsigned int state)
                                        conn_in_list = 0;
                        }
                        else {
-                               conn_delete_from_tree(conn);
+                               conn_delete_from_tree(conn, tid);
                        }
                }
 
@@ -2676,7 +2676,7 @@ static int spop_process(struct spop_conn *spop_conn)
                /* connections in error must be removed from the idle lists */
                if (conn->flags & CO_FL_LIST_MASK) {
                        HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
-                       conn_delete_from_tree(conn);
+                       conn_delete_from_tree(conn, tid);
                        HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
                }
        }
@@ -2799,7 +2799,7 @@ static struct task *spop_timeout_task(struct task *t, void *context, unsigned in
                 * to steal it from us.
                 */
                if (spop_conn->conn->flags & CO_FL_LIST_MASK)
-                       conn_delete_from_tree(spop_conn->conn);
+                       conn_delete_from_tree(spop_conn->conn, tid);
                else if (spop_conn->conn->flags & CO_FL_SESS_IDLE)
                        session_detach_idle_conn(spop_conn->conn->owner, spop_conn->conn);
 
index 1f17e4a0403326fcf8045ed31d1c785ebda222b8..2ce1151be162d6e076c8c00d7ddb4058077bd8c3 100644 (file)
@@ -7188,7 +7188,7 @@ static int srv_migrate_conns_to_remove(struct server *srv, int thr, int toremove
                        break;
 
                conn = LIST_ELEM(srv->per_thr[thr].idle_conn_list.n, struct connection *, idle_list);
-               conn_delete_from_tree(conn);
+               conn_delete_from_tree(conn, thr);
                MT_LIST_APPEND(&idle_conns[thr].toremove_conns, &conn->toremove_list);
                i++;
        }
@@ -7263,7 +7263,7 @@ void srv_release_conn(struct server *srv, struct connection *conn)
        /* Remove the connection from any tree (safe, idle or available) */
        if (conn->hash_node) {
                HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
-               conn_delete_from_tree(conn);
+               conn_delete_from_tree(conn, tid);
                conn->flags &= ~CO_FL_LIST_MASK;
                HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
        }
@@ -7361,7 +7361,7 @@ int srv_add_to_idle_list(struct server *srv, struct connection *conn, int is_saf
                _HA_ATOMIC_DEC(&srv->curr_used_conns);
 
                HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
-               conn_delete_from_tree(conn);
+               conn_delete_from_tree(conn, tid);
 
                if (is_safe) {
                        conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_SAFE_LIST;
@@ -7523,7 +7523,7 @@ static void srv_close_idle_conns(struct server *srv)
 
                                if (conn->ctrl->ctrl_close)
                                        conn->ctrl->ctrl_close(conn);
-                               conn_delete_from_tree(conn);
+                               conn_delete_from_tree(conn, i);
                        }
                }
        }
index 5c320987f1ce287fff26cb6c42d41224c3ab5659..e77d8eeef13b17309abdf7bf4ef16aad8c38727d 100644 (file)
@@ -6422,7 +6422,7 @@ struct task *ssl_sock_io_cb(struct task *t, void *context, unsigned int state)
                                        conn_in_list = 0;
                        }
                        else {
-                               conn_delete_from_tree(conn);
+                               conn_delete_from_tree(conn, tid);
                        }
                }