]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: cache/htx: Fix the counting of data already sent by the cache applet
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 11 Jun 2019 07:58:09 +0000 (09:58 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 11 Jun 2019 12:05:25 +0000 (14:05 +0200)
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

index d63cc790bdd9182bcb63d6e5c0a441596999c293..3504fbaa4624187b3db9f1aec17d843cacd6a365 100644 (file)
@@ -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;