]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: session: streamline session_check_idle_conn() usage
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 30 Jul 2025 09:56:05 +0000 (11:56 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 30 Jul 2025 14:13:30 +0000 (16:13 +0200)
session_check_idle_conn() is called by muxes when a connection becomes
idle. It ensures that the session idle limit is not yet reached. Else,
the connection is removed from the session and it can be freed.

Prior to this patch, session_check_idle_conn() was compatible with a
NULL session argument. In this case, it would return true, considering
that no limit was reached and connection not removed.

However, this renders the function error-prone and subject to future
bugs. This patch streamlines it by ensuring it is never called with a
NULL argument. Thus it can now only returns true if connection is kept
in the session or false if it was removed, as first intended.

include/haproxy/session.h

index 6b1824aba68f42610bad92c2e1b8052f15ed82df..225041a337f8de5cd1ef4ca2fbaff539d5663620 100644 (file)
@@ -226,16 +226,15 @@ static inline int session_add_conn(struct session *sess, struct connection *conn
 }
 
 /* Check that session <sess> is able to keep idle connection <conn>. This must
- * be called after insertion of a private connection into session unless
- * connection is or will be soon active.
+ * be called each time a connection stored in a session becomes idle.
  *
- * Returns 0 if the connection is kept or is not attached to the session, else
- * non-zero if the connection was explicitely removed from session.
+ * Returns 0 if the connection is kept, else non-zero if the connection was
+ * explicitely removed from session.
  */
 static inline int session_check_idle_conn(struct session *sess, struct connection *conn)
 {
-       /* A connection cannot be attached to multiple sessions. */
-       BUG_ON(conn->owner && conn->owner != sess);
+       /* Connection must be attached to session prior to this function call. */
+       BUG_ON(!conn->owner || conn->owner != sess);
 
        /* Connection is not attached to a session. */
        if (!conn->owner)