]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: mux-h2: don't lose EOM when the output buffer is full
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 08:27:04 +0000 (09:27 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 12:41:06 +0000 (13:41 +0100)
When a NOOP block carrying the EOM flag was processed by h2_snd_buf(), an
empty DATA frame with the ES flag was emitted to report the end of the
message. But if this frame could not be emitted, because the output buffer
was full or could not be allocated, the NOOP block was removed anyway and
counted as sent. So the end of the message was lost and the END_STREAM was
never sent. This could happen when the END_STREAM was received in a
separate empty DATA frame (or a standalone FIN for H3) while the H2
connection was congested. A server waiting for the end of the request could
then wait until a timeout. On the client side, the END_STREAM was only sent
on the stream shutdown.

Now, the NOOP block is kept when the empty DATA frame cannot be emitted.
The stream is blocked, like for other blocks, and it will be retried when
some room is made in the output buffer.

This patch must be backported to 3.5.

src/mux_h2.c

index 7337a57a4de4f0cbf8508d873b5dd8ad860ea839..7d44f107b814967a425f80cfd4fc2a365fdc8147 100644 (file)
@@ -8564,12 +8564,17 @@ static size_t h2_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, in
                                if (blk->flags & HTX_BLK_FL_EOM) {
                                        h2s->flags &= ~H2_SF_MORE_HTX_DATA;
                                        if (!(h2s->flags & H2_SF_BODY_TUNNEL)) {
-                                               if (h2_send_empty_data_es(h2s) > 0) {
-                                                       if (h2s->st == H2_SS_OPEN)
-                                                               h2s->st = H2_SS_HLOC;
-                                                       else
-                                                               h2s_close(h2s);
-                                               }
+                                               /* If the empty DATA frame cannot be
+                                                * emitted (no room or error), the
+                                                * NOOP block must be kept to not
+                                                * lose the end of the message.
+                                                */
+                                               if (h2_send_empty_data_es(h2s) <= 0)
+                                                       goto done;
+                                               if (h2s->st == H2_SS_OPEN)
+                                                       h2s->st = H2_SS_HLOC;
+                                               else
+                                                       h2s_close(h2s);
                                        }
                                }
                                htx_remove_blk(htx, blk);