Skip to content

Commit

Permalink
BUG/MINOR: cache: Remove incomplete entries from the cache when strea…
Browse files Browse the repository at this point in the history
…m is closed

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.

(cherry picked from commit 23c810d)
[cf: Adapted for 2.8]
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
  • Loading branch information
rlebreton authored and capflam committed Dec 5, 2023
1 parent ecd3225 commit f5c2470
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,17 @@ 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;

shctx_lock(shctx);
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.
*/
delete_entry(object);
}
shctx_row_dec_hot(shctx, st->first_block);
shctx_unlock(shctx);
}
Expand Down

0 comments on commit f5c2470

Please sign in to comment.