]> git.kaiwu.me - haproxy.git/commit
BUG/MEDIUM: mux-h1: don't swap buffers for a chunk that cannot be framed
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 2 Dec 2026 15:11:39 +0000 (16:11 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 12:41:06 +0000 (13:41 +0100)
commit0c1fcfbf1498e8be8ba3bc85bfedf9a277cd4fc3
treea9e0b078a8c408c4ab9e6cac9bf19ccc1a3193c1
parentdd7eb24a518293c72ccf45e220c7e4ad85d62c0f
BUG/MEDIUM: mux-h1: don't swap buffers for a chunk that cannot be framed

When a chunked message is sent and a new chunk is started in the zero-copy
path of h1_make_data(), the chunk size is taken from the <kop> hint of the
sedesc when it is set. Since the commit e582abe8a ("BUG/MEDIUM: mux-h1:
never forward more data than announced in a chunk"), an error is reported
if the DATA block is bigger than the announced chunk size. But this check,
like the other ones on the chunk size, was performed after the buffers were
swapped and the chunk size was prepended. So the output buffer already
contained the chunk size line followed by more data than announced, and it
was sent anyway. The response was cut and the client waited for the end of
the chunk until the client timeout.

However, <kop> is only a minimal guarantee. It may be lower than the DATA
block, for instance when the end of a chunk and the beginning of the next
one are merged in the same block, after some data were forwarded
mid-chunk, like when the cache stops storing a response exceeding the
maximum object size. It is not an error. The copy path properly handles
this case by splitting the block.

So now, the conditions to perform the zero-copy are evaluated in a
dedicated function, h1_zero_copy_data_allowed(), before swapping the
buffers. For chunked messages, it is only performed if the whole block fits
in the current chunk or in the new one, and if the end of the message
matches the end of the chunk. Otherwise, the copy path is used. It splits
the block or reports the error before anything is emitted. The checks on
the chunk size performed after the buffers swap are useless now and are
removed. Messages with a content-length are not changed: the check on the
announced length is still performed after the buffers swap, but an error
there is a real protocol error.

The commit above was introduced in 3.5-dev14 and was marked to be
backported as far as 3.3. This patch must be backported with it, so to
3.5, and as far as 3.3 where the commit above was backported.
src/mux_h1.c