]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: mux-h2: emit the end of stream in h2_done_ff() on EOI without data
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 09:58:06 +0000 (10:58 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 12:41:07 +0000 (13:41 +0100)
When the producer reports the end of input during a fast-forward without
any data, h2_done_ff() left without emitting anything. It happens for
instance when a close-delimited H1 message is fast-forwarded and the
read0 is detected while no data were received. The end of the stream was
then only reported by h2_do_shutw(), on shutdown, delaying it for no
reason.

Now, in that case, an empty DATA frame with the ES flag is emitted. If it
cannot be emitted, it is still left to h2_do_shutw().

This patch could be backported to all stable versions supporting the
zero-copy forwarding (3.0 and above).

src/mux_h2.c

index 7d44f107b814967a425f80cfd4fc2a365fdc8147..e91fe679ca6d7ef2f5d539a60d52460cfcd315ab 100644 (file)
@@ -8823,19 +8823,27 @@ static size_t h2_done_ff(struct stconn *sc)
                h2s->flags &= ~H2_SF_MORE_HTX_DATA;
        }
 
-       if (!sd->iobuf.data)
+       if (sd->iobuf.data) {
+               total = sd->iobuf.data;
+               h2_set_frame_size(head, total);
+               if (es_now)
+                       head[4] |= H2_F_DATA_END_STREAM;
+               b_add(mbuf, 9);
+               h2s->sws -= total;
+               h2c->mws -= total;
+       }
+       else if (!es_now || h2_send_empty_data_es(h2s) <= 0) {
+               /* Nothing was forwarded. On EOI, the end of the stream is
+                * reported using an empty DATA frame. The room reserved for
+                * the frame header by h2_nego_ff() is still there, so it
+                * should not fail. Otherwise, it will be emitted on shutdown.
+                */
                goto end;
+       }
 
        /* Perform a synchronous send but in all cases, consider
         * everything was already sent from the SC point of view.
         */
-       total = sd->iobuf.data;
-       h2_set_frame_size(head, total);
-       if (es_now)
-               head[4] |= H2_F_DATA_END_STREAM;
-       b_add(mbuf, 9);
-       h2s->sws -= total;
-       h2c->mws -= total;
        if (h2_send(h2s->h2c))
                tasklet_wakeup(h2s->h2c->wait_event.tasklet);