From: Olivier Houchard Date: Thu, 26 Nov 2026 14:22:08 +0000 (+0100) Subject: BUG/MEDIUM: mux-h2: don't block other streams while waiting for a tunnel X-Git-Url: https://git.kaiwu.me/http/%22../static/control.html?a=commitdiff_plain;h=a23a0f1b69b4ea428b7f93fa1c7f1f9f80217be3;p=haproxy.git BUG/MEDIUM: mux-h2: don't block other streams while waiting for a tunnel On the backend side, a stream with data to send for a CONNECT before the server's response is blocked with H2_SF_BLK_MBUSY but stays in the send_list, and h2_snd_buf() and h2_nego_ff() make the other streams wait as long as this list is not empty. So all the other streams of the connection, possibly from other clients with "http-reuse always", are blocked until the server responds. It can be reproduced with a CONNECT followed by a DATA frame sent to a server which delays its response, and a GET on the same backend connection. The send_list is only for streams which are ready to write. Let's use a dedicated flag, H2_SF_WAIT_TUNNEL, not part of H2_SF_BLK_ANY, for which the stream leaves the send_list and is only added back once the tunnel is established or aborted. This was introduced in 2.4 by commit f95f87650 ("MEDIUM: mux-h2: Block client data on server side waiting tunnel establishment"), and must be backported to all supported versions. --- diff --git a/include/haproxy/mux_h2-t.h b/include/haproxy/mux_h2-t.h index 502b3071e..19283d545 100644 --- a/include/haproxy/mux_h2-t.h +++ b/include/haproxy/mux_h2-t.h @@ -129,6 +129,7 @@ static forceinline char *h2c_show_flags(char *buf, size_t len, const char *delim #define H2_SF_WANT_SHUTR 0x00008000 // a stream couldn't shutr() (mux full/busy) #define H2_SF_WANT_SHUTW 0x00010000 // a stream couldn't shutw() (mux full/busy) +#define H2_SF_WAIT_TUNNEL 0x00020000 // data blocked until the tunnel is established or aborted (not in send list) #define H2_SF_EXT_CONNECT_SENT 0x00040000 // rfc 8441 an Extended CONNECT has been sent #define H2_SF_EXT_CONNECT_RCVD 0x00080000 // rfc 8441 an Extended CONNECT has been received and parsed @@ -154,7 +155,8 @@ static forceinline char *h2s_show_flags(char *buf, size_t len, const char *delim _(H2_SF_BODY_TUNNEL, _(H2_SF_NOTIFIED, _(H2_SF_HEADERS_SENT, _(H2_SF_OUTGOING_DATA, _(H2_SF_HEADERS_RCVD, _(H2_SF_WANT_SHUTR, _(H2_SF_WANT_SHUTW, _(H2_SF_EXT_CONNECT_SENT, _(H2_SF_EXT_CONNECT_RCVD, - _(H2_SF_TUNNEL_ABRT, _(H2_SF_MORE_HTX_DATA, _(H2_SF_EXPECT_RXDATA)))))))))))))))))))))); + _(H2_SF_TUNNEL_ABRT, _(H2_SF_MORE_HTX_DATA, _(H2_SF_EXPECT_RXDATA, + _(H2_SF_WAIT_TUNNEL))))))))))))))))))))))); /* epilogue */ _(~0U); return buf; diff --git a/src/mux_h2.c b/src/mux_h2.c index 1bf9905da..08e5a404d 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -1831,6 +1831,24 @@ static void __maybe_unused h2s_notify_send(struct h2s *h2s) } } +/* Blocks until its tunnel is established or aborted. It cannot write, + * so it leaves the send list, unless a shut is pending. + */ +static inline void h2s_wait_tunnel(struct h2s *h2s) +{ + h2s->flags |= H2_SF_WAIT_TUNNEL; + if (!(h2s->flags & (H2_SF_WANT_SHUTR | H2_SF_WANT_SHUTW))) + h2_remove_from_list(h2s); +} + +/* Unblocks , back to the send list if it was waiting to send */ +static inline void h2s_resume_tunnel(struct h2s *h2s) +{ + h2s->flags &= ~H2_SF_WAIT_TUNNEL; + if (!LIST_INLIST(&h2s->list) && h2s->subs && (h2s->subs->events & SUB_RETRY_SEND)) + LIST_APPEND(&h2s->h2c->send_list, &h2s->list); +} + /* alerts the data layer by waking it up. TASK_WOKEN_MSG state is used by * default and if the data layer is also subscribed to recv or send, * TASK_WOKEN_IO is added. But first of all, we check if the shut tasklet must @@ -4005,10 +4023,10 @@ static struct h2s *h2c_bck_handle_headers(struct h2c *h2c, struct h2s *h2s) * the tunnel establishment or the end of the response of an oborted * tunnel */ - if ((h2s->flags & (H2_SF_BODY_TUNNEL|H2_SF_BLK_MBUSY)) == (H2_SF_BODY_TUNNEL|H2_SF_BLK_MBUSY) || - (h2s->flags & (H2_SF_TUNNEL_ABRT|H2_SF_ES_RCVD|H2_SF_BLK_MBUSY)) == (H2_SF_TUNNEL_ABRT|H2_SF_ES_RCVD|H2_SF_BLK_MBUSY)) { + if ((h2s->flags & (H2_SF_BODY_TUNNEL|H2_SF_WAIT_TUNNEL)) == (H2_SF_BODY_TUNNEL|H2_SF_WAIT_TUNNEL) || + (h2s->flags & (H2_SF_TUNNEL_ABRT|H2_SF_ES_RCVD|H2_SF_WAIT_TUNNEL)) == (H2_SF_TUNNEL_ABRT|H2_SF_ES_RCVD|H2_SF_WAIT_TUNNEL)) { TRACE_STATE("Unblock h2s blocked on tunnel establishment/abort", H2_EV_RX_FRAME|H2_EV_RX_DATA, h2c->conn, h2s); - h2s->flags &= ~H2_SF_BLK_MBUSY; + h2s_resume_tunnel(h2s); } TRACE_USER("rcvd H2 response ", H2_EV_RX_FRAME|H2_EV_RX_HDR, h2c->conn, 0, h2s_rxbuf_tail(h2s)); @@ -4144,9 +4162,9 @@ static int h2c_handle_data(struct h2c *h2c, struct h2s *h2s) * aborted tunnel */ if ((h2c->flags & H2_CF_IS_BACK) && - (h2s->flags & (H2_SF_TUNNEL_ABRT|H2_SF_ES_RCVD|H2_SF_BLK_MBUSY)) == (H2_SF_TUNNEL_ABRT|H2_SF_ES_RCVD|H2_SF_BLK_MBUSY)) { + (h2s->flags & (H2_SF_TUNNEL_ABRT|H2_SF_ES_RCVD|H2_SF_WAIT_TUNNEL)) == (H2_SF_TUNNEL_ABRT|H2_SF_ES_RCVD|H2_SF_WAIT_TUNNEL)) { TRACE_STATE("Unblock h2s blocked on tunnel abort", H2_EV_RX_FRAME|H2_EV_RX_DATA, h2c->conn, h2s); - h2s->flags &= ~H2_SF_BLK_MBUSY; + h2s_resume_tunnel(h2s); } TRACE_LEAVE(H2_EV_RX_FRAME|H2_EV_RX_DATA, h2c->conn, h2s); @@ -7650,7 +7668,7 @@ static size_t h2s_make_data(struct h2s *h2s, struct buffer *buf, size_t count) * is not fully established yet. In this situation, we block * data sending. */ - h2s->flags |= H2_SF_BLK_MBUSY; + h2s_wait_tunnel(h2s); TRACE_STATE("Request DATA frame blocked waiting for tunnel establishment", H2_EV_TX_FRAME|H2_EV_TX_DATA, h2c->conn, h2s); goto end; } @@ -7662,7 +7680,7 @@ static size_t h2s_make_data(struct h2s *h2s, struct buffer *buf, size_t count) */ if (!(h2s->flags & H2_SF_ES_RCVD)) { TRACE_STATE("Request DATA frame blocked waiting end of aborted tunnel", H2_EV_TX_FRAME|H2_EV_TX_DATA, h2c->conn, h2s); - h2s->flags |= H2_SF_BLK_MBUSY; + h2s_wait_tunnel(h2s); } else { TRACE_ERROR("Request DATA frame for aborted tunnel", H2_EV_TX_FRAME|H2_EV_TX_DATA, h2c->conn, h2s); @@ -8245,7 +8263,7 @@ static int h2_subscribe(struct stconn *sc, int event_type, struct wait_event *es * he could, this is obviously obsolete. */ h2s->flags &= ~H2_SF_NOTIFIED; - if (!(h2s->flags & H2_SF_BLK_SFCTL) && + if (!(h2s->flags & (H2_SF_BLK_SFCTL|H2_SF_WAIT_TUNNEL)) && !LIST_INLIST(&h2s->list)) { if (h2s->flags & H2_SF_BLK_MFCTL) { TRACE_DEVEL("Adding to fctl list", H2_EV_STRM_SEND, h2c->conn, h2s); @@ -8489,7 +8507,7 @@ static size_t h2_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, in eb32_insert(&h2s->h2c->streams_by_id, &h2s->by_id); } - while (h2s->st < H2_SS_HLOC && !(h2s->flags & H2_SF_BLK_ANY) && + while (h2s->st < H2_SS_HLOC && !(h2s->flags & (H2_SF_BLK_ANY|H2_SF_WAIT_TUNNEL)) && count && !htx_is_empty(htx)) { idx = htx_get_head(htx); blk = htx_get_blk(htx, idx);