From: Amaury Denoyelle Date: Wed, 30 Jul 2025 09:56:05 +0000 (+0200) Subject: MINOR: session: streamline session_check_idle_conn() usage X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2ecc5290f2204e9a1f020caaa18f0608c1191912;p=thirdparty%2Fhaproxy.git MINOR: session: streamline session_check_idle_conn() usage 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. --- diff --git a/include/haproxy/session.h b/include/haproxy/session.h index 6b1824aba..225041a33 100644 --- a/include/haproxy/session.h +++ b/include/haproxy/session.h @@ -226,16 +226,15 @@ static inline int session_add_conn(struct session *sess, struct connection *conn } /* Check that session is able to keep idle connection . 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)