]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: mux-h1: fix the open streams counter on stream creation failure
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 7 Oct 2026 08:59:17 +0000 (10:59 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 16 Oct 2026 17:10:26 +0000 (19:10 +0200)
The "h1_open_streams" stats counter is incremented at the end of
h1c_frt_stream_new() and h1c_bck_stream_new(), and decremented in
h1s_destroy(). But when the stream connector attachment or the sedesc
allocation fails after h1s_new() succeeded, h1s_destroy() is called on the
error path and decrements the counter which was not incremented. The gauge
then drifts and may become negative.

The counter is now incremented in h1s_new() as soon as the H1 stream is
allocated, so that it is always balanced by h1s_destroy(). The total streams
counter is left where it was so that it only counts successfully created
streams.

This patch may be backported to all supported versions.

src/mux_h1.c

index 9eea1e39fe480297e22f0976f63f6c409e77eca9..2c30ae8a6bd8fab6b38c34d2fc61fb9d7411d5bf 100644 (file)
@@ -950,6 +950,8 @@ static struct h1s *h1s_new(struct h1c *h1c)
        }
        h1s->h1c = h1c;
        h1c->h1s = h1s;
+       /* must be done here since decremented by h1s_destroy() */
+       HA_ATOMIC_INC(&h1c->px_counters->open_streams);
        h1s->sess = NULL;
        h1s->sd = NULL;
        h1s->flags = H1S_F_WANT_KAL;
@@ -1014,7 +1016,6 @@ static struct h1s *h1c_frt_stream_new(struct h1c *h1c, struct stconn *sc, struct
        if (h1c->px->options2 & PR_O2_REQBUG_OK)
                h1s->req.err_pos = -1;
 
-       HA_ATOMIC_INC(&h1c->px_counters->open_streams);
        HA_ATOMIC_INC(&h1c->px_counters->total_streams);
 
        h1c->idle_exp = TICK_ETERNITY;
@@ -1054,7 +1055,6 @@ static struct h1s *h1c_bck_stream_new(struct h1c *h1c, struct stconn *sc, struct
        if (h1c->px->options2 & PR_O2_RSPBUG_OK)
                h1s->res.err_pos = -1;
 
-       HA_ATOMIC_INC(&h1c->px_counters->open_streams);
        HA_ATOMIC_INC(&h1c->px_counters->total_streams);
 
        TRACE_STATE("created new H1 back stream", H1_EV_H1S_NEW, h1c->conn, h1s);