]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MAJOR: mux-h2: fail on impossible data transfers in rcv_buf()
authorWilly Tarreau <w@1wt.eu>
Tue, 17 Nov 2026 17:27:58 +0000 (18:27 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 17 Nov 2026 17:38:15 +0000 (18:38 +0100)
When some data couldn't be transferred from the rxbuf to the channel,
leaving the channel empty (e.g. due to the reserve), we must not set
SE_FL_WANT_ROOM otherwise we cannot get out of this situation. There's
even already a BUG_ON() for this. However it turns out that in some
tricky circumstances it can be triggered. The test is thus not correct
and instead we should simply report a stream error.

This needs to be backported as far as 2.6.

Many thanks to Adam Crawford for reporting this issue along with a
repro and a candidate fix. In the end the current fix is different
as it addresses the root cause (WANT_ROOM + no-data) so it should
be more future-proof.

src/mux_h2.c

index 2e18eea3fe90b4cf166a30bba96e140b2ae16c06..3f9e33bc4747a791a388460928b941c6aaf4b526 100644 (file)
@@ -8339,8 +8339,16 @@ static size_t h2_rcv_buf(struct stconn *sc, struct buffer *buf, size_t count, in
 
        /* tell the stream layer whether there are data left or not */
        if (h2s_rxbuf_cnt(h2s)) {
+               if (!buf->data) {
+                       /* we have pending data and the output buf is empty,
+                        * this is typical of too large a non-fragmentable
+                        * data (e.g headers, trailers) combined with a
+                        * reserve, so this will never unblock.
+                        */
+                       se_fl_set(h2s->sd, SE_FL_ERROR);
+                       goto leave;
+               }
                se_fl_set(h2s->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM);
-               BUG_ON_HOT(!buf->data);
        }
        else {
                if (!(h2c->flags & H2_CF_IS_BACK) && (h2s->flags & (H2_SF_BODY_TUNNEL|H2_SF_ES_RCVD))) {
@@ -8364,6 +8372,7 @@ static size_t h2_rcv_buf(struct stconn *sc, struct buffer *buf, size_t count, in
 
        BUG_ON_HOT(!buf->data && se_fl_test(h2s->sd, SE_FL_WANT_ROOM));
 
+ leave:
        TRACE_LEAVE(H2_EV_STRM_RECV, h2c->conn, h2s);
        return ret;
 }