From: Olivier Houchard Date: Fri, 20 Nov 2026 13:29:45 +0000 (+0100) Subject: BUG/MEDIUM: mux-h2: don't stall on a failed rxbuf alloc without stream X-Git-Url: https://git.kaiwu.me/http/%7B@url%7D?a=commitdiff_plain;h=830bbaa7ad28da86afb7c47a457d76e224d51704;p=haproxy.git BUG/MEDIUM: mux-h2: don't stall on a failed rxbuf alloc without stream When h2c_dec_hdrs() fails to allocate the temporary buffer used to decode the HEADERS frame of a new request, it sets H2_CF_DEM_SALLOC and the connection is queued in the buffer wait list. But h2_buf_available() only serves H2_CF_DEM_SALLOC for a stream which has a stream connector, which is not the case yet, so it never succeeds: the demux remains blocked and the request is not processed until the connection times out. This can be reproduced by faking a failed allocation there on the first request of a connection. There is no buffer the callback could allocate in this case, so let's clear the flag and restart the demux, which will retry by itself. Since b_alloc() refuses to allocate when other entries are queued, the retry would be queued again and the offered buffer would be lost for everyone, so a new flag H2_CF_DEM_MAYALLOC is set to let the next h2_get_buf() allocate with DB_F_NOQUEUE, as mux-h1 does with H1C_F_IN_MAYALLOC. This was introduced in 2.0 by commit 5c8cafae3 ("MEDIUM: mux-h2: decode HEADERS frames before allocating the stream"). It must be backported to all supported versions. Before 3.0 there is no DB_F_NOQUEUE and the new flag is not needed, clearing H2_CF_DEM_SALLOC and restarting the demux is enough. --- diff --git a/include/haproxy/mux_h2-t.h b/include/haproxy/mux_h2-t.h index fd8f5abd8..502b3071e 100644 --- a/include/haproxy/mux_h2-t.h +++ b/include/haproxy/mux_h2-t.h @@ -73,6 +73,7 @@ #define H2_CF_IDL_PING 0x04000000 // timer task scheduled for a PING emission #define H2_CF_IDL_PING_SENT 0x08000000 // PING emitted, or will be on next tasklet run, waiting for ACK +#define H2_CF_DEM_MAYALLOC 0x10000000 // demux may allocate its next buffer despite the queue /* This function is used to report flags in debugging tools. Please reflect * below any single-bit flag addition above in the same order via the @@ -91,7 +92,7 @@ static forceinline char *h2c_show_flags(char *buf, size_t len, const char *delim _(H2_CF_GOAWAY_SENT, _(H2_CF_GOAWAY_FAILED, _(H2_CF_WAIT_FOR_HS, _(H2_CF_IS_BACK, _(H2_CF_WINDOW_OPENED, _(H2_CF_RCVD_SHUT, _(H2_CF_END_REACHED, _(H2_CF_RCVD_RFC8441, _(H2_CF_SHTS_UPDATED, _(H2_CF_DTSU_EMITTED, - _(H2_CF_ERR_PENDING, _(H2_CF_ERROR))))))))))))))))))))))))); + _(H2_CF_ERR_PENDING, _(H2_CF_ERROR, _(H2_CF_DEM_MAYALLOC)))))))))))))))))))))))))); /* epilogue */ _(~0U); return buf; diff --git a/src/mux_h2.c b/src/mux_h2.c index 920ee1c13..8dd296ade 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -1292,6 +1292,15 @@ static int h2_buf_available(void *target) progress = 1; } + if ((h2c->flags & H2_CF_DEM_SALLOC) && + !h2s_sc(h2c_st_by_id(h2c, h2c->dsi))) { + /* no stream to allocate for, let the demux retry */ + h2c->flags &= ~H2_CF_DEM_SALLOC; + h2c->flags |= H2_CF_DEM_MAYALLOC; + h2c_restart_reading(h2c, 1); + progress = 1; + } + if ((h2c->flags & H2_CF_DEM_SALLOC) && (h2s = h2c_st_by_id(h2c, h2c->dsi)) && h2s_sc(h2s) && (h2s_rxbuf_tail(h2s) || h2s_get_rxbuf(h2s))) { @@ -1321,9 +1330,12 @@ static inline struct buffer *h2_get_buf(struct h2c *h2c, struct buffer *bptr) if (b_size(bptr)) return bptr; - if (likely(!LIST_INLIST(&h2c->buf_wait.list)) && - unlikely((buf = b_alloc(bptr, DB_MUX_RX)) == NULL)) { - b_queue(DB_MUX_RX, &h2c->buf_wait, h2c, h2_buf_available); + if (likely(!LIST_INLIST(&h2c->buf_wait.list))) { + buf = b_alloc(bptr, DB_MUX_RX | + ((h2c->flags & H2_CF_DEM_MAYALLOC) ? DB_F_NOQUEUE : 0)); + h2c->flags &= ~H2_CF_DEM_MAYALLOC; + if (unlikely(!buf)) + b_queue(DB_MUX_RX, &h2c->buf_wait, h2c, h2_buf_available); } return buf; }