]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: mux-fcgi: don't add a closed connection to an idle list on detach
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 6 Nov 2026 09:49:35 +0000 (10:49 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 9 Nov 2026 12:33:52 +0000 (13:33 +0100)
In fcgi_detach(), the test deciding whether the connection may be moved to
an idle list checks FCGI_CF_EOS, FCGI_CF_ERR_PENDING, FCGI_CF_ERROR and
FCGI_CF_KEEP_CONN, but not the connection state. A connection that already
switched to FCGI_CS_CLOSED may thus be inserted in the session server list
or in the server's idle pool, while fcgi_avail_streams() reports no
available stream for it. The stream immediately before, in the same
function, does test FCGI_CS_CLOSED.

This can currently only happen with a private connection, since
srv_add_to_idle_list() already rejects connections without available
streams, and it is not harmful either way: session_get_conn() also
requires an available stream, so such a connection is never reused. But
it is still wrong to park it, since it prevents the session from
dropping it and forces a useless idle counter increment.

Note that fcgi_conn_is_dead() must not be used here: it also requires
FCGI_CF_KEEP_CONN to be cleared or FCGI_CF_ERROR to be set, so it does not
cover every FCGI_CS_CLOSED connection, and the non-private branch below
clears conn->owner before parking the connection.

This may be backported to all supported versions.

src/mux_fcgi.c

index c471e2a769ee7aae4ea242300538ad5ebb2c5d41..028792e34cd7bf38937d01020fb3ef575957f43c 100644 (file)
@@ -3859,6 +3859,7 @@ static void fcgi_detach(struct sedesc *sd)
        fcgi_conn_update_timeout(fconn);
 
        if (!(fconn->flags & (FCGI_CF_EOS|FCGI_CF_ERR_PENDING|FCGI_CF_ERROR)) &&
+           (fconn->state != FCGI_CS_CLOSED) &&
            (fconn->flags & FCGI_CF_KEEP_CONN)) {
                if (fconn->conn->flags & CO_FL_PRIVATE) {
                        /* Add the connection in the session serverlist, if not already done */