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.
This commit is contained in:
Amaury Denoyelle 2025-07-30 11:56:05 +02:00
parent dd9645d6b9
commit 2ecc5290f2

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