]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: session: strengthen connection attach to session
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 23 Jul 2025 08:03:51 +0000 (10:03 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 30 Jul 2025 09:39:26 +0000 (11:39 +0200)
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().

include/haproxy/session.h

index f0731c711c2bd2899972c55d2a83d946164684e2..cb0b6e7b5ee313d140ea8e714f786a0fe245ab91 100644 (file)
@@ -173,8 +173,7 @@ static inline void session_unown_conn(struct session *sess, struct connection *c
 
 /* Add the connection <conn> to the private conns list of session <sess>. 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) {