]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: flt-decomp: allocate the buffer to emit pending data
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 2 Dec 2026 14:11:12 +0000 (15:11 +0100)
committerOlivier Houchard <cognet@ci0.org>
Wed, 2 Dec 2026 14:33:02 +0000 (15:33 +0100)
When the decompressed data do not fit in the buffer, the remaining ones
are emitted on a next call. But once the first part was sent, the
channel buffer may have been released, and in this case nothing could be
emitted and the message was stuck. This happens with requests whose EOM
is carried by the last DATA block (content-length in H1, or H2) when
this block is decompressed into more than a buffer, e.g. 30kB of text:
the client gets a 504.

Now the buffer is allocated when the filter still has something to emit.
Since the HTX message seen by the caller changes in this case, it is now
retrieved again after the call to the filters, in both
http_request_forward_body() and http_response_forward_body(). The filter
was introduced in 3.5-dev6, so no backport is needed.

src/flt_decomp.c
src/http_ana.c

index 2a781ceb2d833bc4af7cf099bdfedf3498c357e5..5603f615599c28da40f7a32318ed5d80e33dbb5f 100644 (file)
@@ -244,6 +244,13 @@ static int decomp_stream_blk(struct stream *s, struct filter *f, struct channel
                goto end;
        }
 
+       /* the buffer may have been released while data are still to be emitted */
+       if (!b_size(&chn->buf) && (st->decomp_ctx->drain_len || (st->flags & DECOMP_STATE_EOM_SEEN))) {
+               if (!channel_alloc_buffer(chn, &s->buffer_wait))
+                       goto end;
+               htx = htx_from_buf(&chn->buf);
+       }
+
        htxret = htx_find_offset(htx, offset);
        offset = htxret.ret;
        blk = htxret.blk;
index 6ff4fba44ccbb898902358543da5302f8201ce70..c2f23821d22811a8b81019f3ffba05a12a1620e1 100644 (file)
@@ -1017,6 +1017,8 @@ int http_request_forward_body(struct stream *s, struct channel *req, int an_bit)
                ret  = flt_http_payload(s, msg, htx->data);
                if (ret < 0)
                        goto return_bad_req;
+               /* a filter may have allocated the buffer */
+               htx = htxbuf(&req->buf);
                c_adv(req, ret);
        }
        else {
@@ -2269,6 +2271,8 @@ int http_response_forward_body(struct stream *s, struct channel *res, int an_bit
                ret  = flt_http_payload(s, msg, htx->data);
                if (ret < 0)
                        goto return_bad_res;
+               /* a filter may have allocated the buffer */
+               htx = htxbuf(&res->buf);
                c_adv(res, ret);
        }
        else {