]> git.kaiwu.me - haproxy.git/commit
BUG/MEDIUM: cache: do not release an entry under the cache read lock
authorRémi Tricot-Le Breton <rlebreton@haproxy.com>
Mon, 10 Aug 2026 15:23:30 +0000 (17:23 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 12 Aug 2026 07:17:56 +0000 (09:17 +0200)
commit6da161c1c7490e1db886643c4b8b5fce590a5987
treedb9bb423516e9770bb37d704eed594cd568f137b
parent99db59551c00ae53a1b593913da594aff0cc5649
BUG/MEDIUM: cache: do not release an entry under the cache read lock

In http_action_req_cache_use() the cache lock is taken in read mode rather
than write mode in order to keep decent performance. But the secondary key
lookup releases the primary entry from there with needs_locking = 0, which
means "the caller already holds the write lock", because dropping the last
reference removes the entry from the tree. A removal could therefore run
while other threads were walking the same tree under their own read lock.

Release the entry after the read-locked section instead, where taking the
write lock for the removal is allowed.

The row is handed back only once the reference has been dropped, and no
longer before: a row that returns to the avail list while a reference is
still held on its entry can be recycled by another thread, and the release
would then be applied to blocks that hold a response body. This is also why
the reattach cannot simply be left where it was.

This is present at least as far back as 3.0 and should be backported to all
stable branches.

Reported-by: Claude (ANT-2026-Y40G33XK)
src/cache.c