]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: flt-decomp: don't forward trailers before 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)
In decomp_stream_blk(), only the EOT block was held while decompressed
data were still pending. TLR blocks, and the NOOP block carrying the EOM
since commit 221c40bbf ("MINOR: htx: Add a noop block to carry the EOM
flag on an empty message"), were forwarded immediately. When the
decompressed data did not all fit in the buffer, the trailers and the
end of the message were thus sent before the remaining data: a chunked
gzip response of 30kB with a trailer was delivered as a complete message
of 15.8kB. In the request direction, it led to a 500 with "IH--".

Now these blocks are handled like the EOT block. In addition, when the
decompression state is flushed on such a block and the decompression is
finished with nothing left to emit, the block is now counted as
forwarded, otherwise the following ones would be counted while this one
is not. The filter was introduced in 3.5-dev6 by commit f0710d808
("MEDIUM: flt-decomp: implement decomp-req and decomp-res filters"), so
no backport is needed.

src/flt_decomp.c

index 7a21d3b83968f439ccc4db85fa8cc70c0d33ff9e..aca1fd97bc26d986038c218f0ff9c5374ba3fb33 100644 (file)
@@ -332,6 +332,11 @@ static int decomp_stream_blk(struct stream *s, struct filter *f, struct channel
                                }
                                break;
 
+                       case HTX_BLK_NOOP:
+                               if (!(blk->flags & HTX_BLK_FL_EOM))
+                                       goto consume;
+                               __fallthrough;
+                       case HTX_BLK_TLR:
                        case HTX_BLK_EOT:
                                if (st->decomp_ctx->drain_len) {
                                        /* there is still pending data that we need to drain */
@@ -348,10 +353,18 @@ static int decomp_stream_blk(struct stream *s, struct filter *f, struct channel
                                        if (ret == -1)
                                                goto error;
 
-                                       break; /* if decomp_ctx->drain_len is set it will be taken
-                                               * care of
-                                               */
-
+                                       /* If some data are pending or if the decompression
+                                        * is not finished, this block and the following
+                                        * ones must not be forwarded yet. Pending data will
+                                        * be drained later, before this block. Otherwise,
+                                        * the decompression is finished with no data left,
+                                        * so this block must be counted as forwarded. It
+                                        * must not be skipped while the following ones are
+                                        * counted.
+                                        */
+                                       if (st->decomp_ctx->drain_len ||
+                                           !(st->decomp_ctx->flags & DECOMP_CTX_FL_DONE))
+                                               break;
                                }
 
                                /* don't forget some out of payload data such as EOT count as forwarded
@@ -362,6 +375,7 @@ static int decomp_stream_blk(struct stream *s, struct filter *f, struct channel
                                break;
 
                        default:
+                         consume:
                                /* nothing to do with that, just forward */
                                total += htx_get_blksz(blk);
                                break;