]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: queue: add a function to check for TOCTOU after queueing
authorWilly Tarreau <w@1wt.eu>
Fri, 26 Jul 2024 17:24:33 +0000 (19:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 29 Jul 2024 07:27:01 +0000 (09:27 +0200)
commit1a8f3a368f1d212f5c2869d400fb07c78b2e7f45
tree105177483ffda4382f07616cc844eb1c42938e41
parent4316ef2eabb7e2474dddcb063d5eaa6359929439
MINOR: queue: add a function to check for TOCTOU after queueing

There's a rare TOCTOU case that happens from time to time with maxconn 1
and multiple threads. Between the moment we see the queue full and the
moment we queue a request, it's possible that the last request on the
server or proxy ended and that no other one is left to offer it its place.

Given that all this code path is performance-critical and we cannot afford
to increase the lock duration, better recheck for the condition after
queueing. For this we need to be able to check for the condition and
cleanly dequeue a request. That's what this patch provides via the new
function pendconn_must_try_again(). It will catch more requests than
absolutely needed though it will catch them all. It may find that around
1/1000 of requests are at risk, though testing shows that in practice,
it's around 1 per million that really gets stuck (other ones benefit
from timing and finishing late requests). Maybe in the future some
conditions might be refined but it's harmless.

What happens to such requests is that they're dequeued and their pendconn
freed, so that the caller can decide to try to LB or queue them again. For
now the function is not used, it's just added separately for easier tracking.
include/haproxy/queue.h
src/queue.c