]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: session: strengthen idle conn limit check
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 30 Jul 2025 07:55:37 +0000 (09:55 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 30 Jul 2025 09:40:16 +0000 (11:40 +0200)
Add a BUG_ON() on session_check_idle_conn() to ensure the connection is
not already flagged as CO_FL_SESS_IDLE.

This checks that this function is only called one time per connection
transition from active to idle. This is necessary to ensure that session
idle counter is only incremented one time per connection.

include/haproxy/session.h

index aa36fa9daa1ea7f3e578bf3f6c22292e942ac3f8..8ec1f7df5596593a6c0e6be0fa37f005d824c059 100644 (file)
@@ -237,16 +237,20 @@ static inline int session_check_idle_conn(struct session *sess, struct connectio
        if (!conn->owner)
                return 0;
 
+       /* Ensure conn is not already accounted as idle to prevent sess idle count excess increment. */
+       BUG_ON(conn->flags & CO_FL_SESS_IDLE);
+
        if (sess->idle_conns >= sess->fe->max_out_conns) {
                session_unown_conn(sess, conn);
                conn->owner = NULL;
-               conn->flags &= ~CO_FL_SESS_IDLE;
                conn->mux->destroy(conn->ctx);
                return -1;
-       } else {
+       }
+       else {
                conn->flags |= CO_FL_SESS_IDLE;
                sess->idle_conns++;
        }
+
        return 0;
 }