MINOR: h3: check connection error during sending
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 22 Dec 2023 10:45:54 +0000 (11:45 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 2 Jan 2024 06:55:12 +0000 (07:55 +0100)
If an error occurs during HTX to H3 encoding, h3_snd_buf() should be
interrupted. This commit add this possibility by checking for <h3c.err>
member value. If non null, sending loop is stopped and an error is
reported using qcc_set_error().

This commit does not change any behavior for now, as <h3c.err> is never
set during sending. However, this will change in future commits, most
notably to reject too many headers or handle buffer allocation failure.
As such, this commit should be backported along the following fixes.
Note that in 2.6 qcc_set_error() does not exist and must be replaced by
qcc_emit_cc_app().

(cherry picked from commit 642016ce033aeb5ccc09b81b98db8046eefd2e2c)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/h3.c

index c849bde..7ff9b10 100644 (file)
--- a/src/h3.c
+++ b/src/h3.c
@@ -1839,6 +1839,8 @@ static int h3_resp_data_send(struct qcs *qcs, struct buffer *buf, size_t count)
 
 static size_t h3_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count)
 {
+       struct h3s *h3s = qcs->ctx;
+       struct h3c *h3c = h3s->h3c;
        size_t total = 0;
        enum htx_blk_type btype;
        struct htx *htx;
@@ -1854,7 +1856,9 @@ static size_t h3_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count)
        if (htx->extra && htx->extra == HTX_UNKOWN_PAYLOAD_LENGTH)
                qcs->flags |= QC_SF_UNKNOWN_PL_LENGTH;
 
-       while (count && !htx_is_empty(htx) && !(qcs->flags & QC_SF_BLK_MROOM)) {
+       while (count && !htx_is_empty(htx) &&
+              !(qcs->flags & QC_SF_BLK_MROOM) && !h3c->err) {
+
                idx = htx_get_head(htx);
                blk = htx_get_blk(htx, idx);
                btype = htx_get_blk_type(blk);
@@ -1905,6 +1909,12 @@ static size_t h3_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count)
                }
        }
 
+       /* Interrupt sending on connection error. */
+       if (unlikely(h3c->err)) {
+               qcc_set_error(qcs->qcc, h3c->err, 1);
+               goto out;
+       }
+
        /* RFC 9114 4.1. HTTP Message Framing
         *
         * A server can send a complete response prior to the client sending an