]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mux-quic: implement max-reuse server parameter
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 19 Nov 2025 10:39:54 +0000 (11:39 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 19 Nov 2025 15:02:22 +0000 (16:02 +0100)
Properly implement support for max-reuse server keyword. This is done by
adding a total count of streams seen for the whole connection. This
value is used in avail_streams callback.

include/haproxy/mux_quic-t.h
src/mux_quic.c

index 34df2c7d9944fec56deb717e0a14a60f50dad4c4..28a8103a52706804a6b4643b4dc861730214f720 100644 (file)
@@ -41,6 +41,7 @@ struct qcc {
        struct connection *conn;
        uint64_t nb_sc; /* number of attached stream connectors */
        uint64_t nb_hreq; /* number of in-progress http requests */
+       uint64_t tot_sc; /* total number of stream connectors seen since conn init */
        uint32_t flags; /* QC_CF_* */
        enum qcc_app_st app_st; /* application layer state */
        int glitches;   /* total number of glitches on this connection */
index 43c6813946a7ce83446d995ae1aa92bd7ac1758c..ffbb663eebbe677a30165c927c15023c47936c3a 100644 (file)
@@ -957,6 +957,7 @@ int qcs_attach_sc(struct qcs *qcs, struct buffer *buf, char fin)
        qcs->flags |= QC_SF_HREQ_RECV;
        ++qcc->nb_sc;
        ++qcc->nb_hreq;
+       ++qcc->tot_sc;
 
        /* TODO duplicated from mux_h2 */
        sess->accept_date = date;
@@ -3132,9 +3133,18 @@ static int qmux_avail_streams(struct connection *conn)
 {
        struct server *srv = __objt_server(conn->target);
        struct qcc *qcc = conn->ctx;
+       int max_fctl, max_reuse = 0;
 
-       BUG_ON(srv->max_reuse >= 0); /* TODO ensure max-reuse is enforced. */
-       return qcc_fctl_avail_streams(qcc, 1);
+       max_fctl = qcc_fctl_avail_streams(qcc, 1);
+
+       if (srv->max_reuse >= 0) {
+               max_reuse = qcc->tot_sc <= srv->max_reuse ?
+                 srv->max_reuse - qcc->tot_sc + 1: 0;
+               return MIN(max_fctl, max_reuse);
+       }
+       else {
+               return max_fctl;
+       }
 }
 
 /* Returns the number of streams currently attached into <conn> connection.
@@ -3600,7 +3610,7 @@ static int qmux_init(struct connection *conn, struct proxy *prx,
 
        _qcc_init(qcc);
        conn->ctx = qcc;
-       qcc->nb_hreq = qcc->nb_sc = 0;
+       qcc->nb_hreq = qcc->nb_sc = qcc->tot_sc = 0;
        qcc->flags = conn_is_back(conn) ? QC_CF_IS_BACK : 0;
        qcc->app_st = QCC_APP_ST_NULL;
        qcc->glitches = 0;
@@ -3771,6 +3781,7 @@ static int qmux_init(struct connection *conn, struct proxy *prx,
                qcs->sess = sess;
                qcs->sd = sc->sedesc;
                qcc->nb_sc++;
+               qcc->tot_sc++;
        }
 
        TRACE_LEAVE(QMUX_EV_QCC_NEW, conn);
@@ -3834,6 +3845,7 @@ static int qmux_strm_attach(struct connection *conn, struct sedesc *sd, struct s
        qcs->sess = sess;
        qcs->sd = sd->sc->sedesc;
        qcc->nb_sc++;
+       qcc->tot_sc++;
 
        /* the connection is not idle anymore, let's mark this */
        HA_ATOMIC_AND(&qcc->wait_event.tasklet->state, ~TASK_F_USR1);