]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: cache: Remove incomplete entries from the cache when stream is closed
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Tue, 28 Nov 2023 16:08:56 +0000 (17:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 28 Nov 2023 16:18:48 +0000 (17:18 +0100)
When a stream is interrupted by the client before the full answer is
stored in the cache, we end up with an incomplete entry in the cache
that cannot be overwritten until it "naturally" expires. In such a case,
we call the cache filter's cache_store_strm_deinit callback without ever
calling cache_store_http_end which means that the 'complete' flag is
never set on the concerned cache_entry.
This patch adds a check on the 'complete' flag in the strm_deinit
callback and removes the entry from the cache if it is incomplete.

A way to exhibit this bug is to try to get the same "big" response on
multiple clients at the same time thanks to h2load for instance, and to
interrupt the client side before the answer can be fully stored in the
cache.

This patch can be backported up to 2.4 but it will need some rework
starting with branch 2.8 because of the latest cache changes.

src/cache.c

index 379c6d7c74057301a8a893940867b32950ae06cb..e436a9ce93d0c4d2b0accc52fdad9e77e204789a 100644 (file)
@@ -667,6 +667,15 @@ cache_store_strm_deinit(struct stream *s, struct filter *filter)
        /* Everything should be released in the http_end filter, but we need to do it
         * there too, in case of errors */
        if (st && st->first_block) {
+               struct cache_entry *object = (struct cache_entry *)st->first_block->data;
+               if (!object->complete) {
+                       /* The stream was closed but the 'complete' flag was not
+                        * set which means that cache_store_http_end was not
+                        * called. The stream must have been closed before we
+                        * could store the full answer in the cache.
+                        */
+                       release_entry_unlocked(&cache->trees[object->eb.key % CACHE_TREE_NUM], object);
+               }
                shctx_wrlock(shctx);
                shctx_row_reattach(shctx, st->first_block);
                shctx_wrunlock(shctx);