]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: mux-h2: Set ES flag when necessary on 0-copy data forwarding
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 27 Aug 2024 17:16:07 +0000 (19:16 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 28 Aug 2024 08:05:34 +0000 (10:05 +0200)
When DATA frames are sent via the 0-copy data forwarding, we must take care
to set the ES flag on the last DATA frame. It should be performed in
h2_done_ff() when IOBUF_FL_EOI flag was set by the producer. This flag is
here to know when the producer has reached the end of input. When this
happens, the h2s state is also updated. It is switched to "half-closed
local" or "closed" state depending on its previous state.

It is mainly an issue on uploads because the server may be blocked waiting
for the end of the request. A workaround is to disable the 0-copy forwarding
support the the H2 by setting "tune.h2.zero-copy-fwd-send" directive to off
in your global section.

This patch should fix the issue #2665. It must be backported as far as 2.9.

src/mux_h2.c

index c8d588f50f3bc7d69a0a8ed3d7f8bae0dd197f62..d6583cc1adf2f8b0fe8f668dc3e5b13a7916879a 100644 (file)
@@ -7372,6 +7372,7 @@ static size_t h2_done_ff(struct stconn *sc)
        struct buffer *mbuf;
        char *head;
        size_t total = 0;
+       int es_now = 0;
 
        TRACE_ENTER(H2_EV_H2S_SEND|H2_EV_STRM_SEND, h2s->h2c->conn, h2s);
 
@@ -7380,8 +7381,10 @@ static size_t h2_done_ff(struct stconn *sc)
                goto end;
        head = b_peek(mbuf, b_data(mbuf) - sd->iobuf.data);
 
-       if (sd->iobuf.flags & IOBUF_FL_EOI)
+       if (sd->iobuf.flags & IOBUF_FL_EOI) {
+               es_now = 1;
                h2s->flags &= ~H2_SF_MORE_HTX_DATA;
+       }
 
        if (!(sd->iobuf.flags & IOBUF_FL_FF_BLOCKED) &&
            !(h2s->flags & H2_SF_BLK_SFCTL) &&
@@ -7398,12 +7401,24 @@ static size_t h2_done_ff(struct stconn *sc)
         */
        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);
 
+       if (es_now) {
+               if (h2s->st == H2_SS_OPEN)
+                       h2s->st = H2_SS_HLOC;
+               else
+                       h2s_close(h2s);
+
+               h2s->flags |= H2_SF_ES_SENT;
+               TRACE_PROTO("ES flag set on outgoing frame", H2_EV_TX_FRAME|H2_EV_TX_DATA|H2_EV_TX_EOI, h2c->conn, h2s);
+       }
+
  end:
        sd->iobuf.buf = NULL;
        sd->iobuf.offset = 0;