From bda8397fba027eaee2c46d566a7e85343dc2de02 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Tue, 11 Jun 2019 09:58:09 +0200 Subject: [PATCH] BUG/MINOR: cache/htx: Fix the counting of data already sent by the cache applet Since the commit 8f3c256f7 ("MEDIUM: cache/htx: Always store info about HTX blocks in the cache"), it is possible to read info about a data block without sending anything. It is possible because we rely on the function htx_add_data(), which will try to add data without any defragmentation. In such case, info about the data block are skipped but don't count in data sent. No need to backport this patch, expect if the commit 8f3c256f7 is backported too. --- src/cache.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/cache.c b/src/cache.c index d63cc790bd..3504fbaa46 100644 --- a/src/cache.c +++ b/src/cache.c @@ -898,7 +898,6 @@ static unsigned int htx_cache_dump_blk(struct appctx *appctx, struct htx *htx, e offset = 0; } } - appctx->ctx.cache.offset = offset; appctx->ctx.cache.next = shblk; appctx->ctx.cache.sent += total; @@ -918,13 +917,16 @@ static unsigned int htx_cache_dump_data_blk(struct appctx *appctx, struct htx *h if (!max) return 0; - total = 0; rem_data = 0; - blksz = ((appctx->ctx.cache.rem_data) - ? appctx->ctx.cache.rem_data - : (info & 0xfffffff)); - if (blksz > max) { + if (appctx->ctx.cache.rem_data) { + blksz = appctx->ctx.cache.rem_data; total = 0; + } + else { + blksz = (info & 0xfffffff); + total = 4; + } + if (blksz > max) { rem_data = blksz - max; blksz = max; } @@ -945,9 +947,6 @@ static unsigned int htx_cache_dump_data_blk(struct appctx *appctx, struct htx *h } } - if (total && !appctx->ctx.cache.rem_data) - total += 4; - appctx->ctx.cache.offset = offset; appctx->ctx.cache.next = shblk; appctx->ctx.cache.sent += total; -- 2.47.3