From: Amaury Denoyelle Date: Wed, 23 Jul 2025 08:03:51 +0000 (+0200) Subject: MINOR: session: strengthen connection attach to session X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=668c2cfb0970f5cb47864095f3c53e752d155ca0;p=thirdparty%2Fhaproxy.git MINOR: session: strengthen connection attach to session This commit is the first one of a serie to refactor insertion of backend private connection into the session list. session_add_conn() is used to attach a connection into a session list. Previously, this function would report an error if the connection specified was already attached to another session. However, this case currently never happens and thus can be considered as buggy. Remove this check and replace it with a BUG_ON(). This allows to ensure that session insertion remains consistent. The same check is also transformed in session_check_idle_conn(). --- diff --git a/include/haproxy/session.h b/include/haproxy/session.h index f0731c711..cb0b6e7b5 100644 --- a/include/haproxy/session.h +++ b/include/haproxy/session.h @@ -173,8 +173,7 @@ static inline void session_unown_conn(struct session *sess, struct connection *c /* Add the connection to the private conns list of session . This * function is called only if the connection is private. Nothing is performed - * if the connection is already in the session list or if the session does not - * owned the connection. + * if the connection is already in the session list. */ static inline int session_add_conn(struct session *sess, struct connection *conn, void *target) { @@ -184,8 +183,11 @@ static inline int session_add_conn(struct session *sess, struct connection *conn BUG_ON(objt_listener(conn->target)); - /* Already attach to the session or not the connection owner */ - if (!LIST_ISEMPTY(&conn->sess_el) || (conn->owner && conn->owner != sess)) + /* A connection cannot be attached already to another session. */ + BUG_ON(conn->owner && conn->owner != sess); + + /* Already attach to the session */ + if (!LIST_ISEMPTY(&conn->sess_el)) return 1; list_for_each_entry(pconns, &sess->priv_conns, sess_el) { @@ -224,8 +226,11 @@ static inline int session_add_conn(struct session *sess, struct connection *conn */ static inline int session_check_idle_conn(struct session *sess, struct connection *conn) { - /* Another session owns this connection */ - if (conn->owner != sess) + /* A connection cannot be attached to multiple sessions. */ + BUG_ON(conn->owner && conn->owner != sess); + + /* Connection is not attached to a session. */ + if (!conn->owner) return 0; if (sess->idle_conns >= sess->fe->max_out_conns) {