]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: queue: Handle the race condition between queue and dequeue differently
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 5 Dec 2024 14:30:06 +0000 (15:30 +0100)
committerOlivier Houchard <cognet@ci0.org>
Tue, 24 Dec 2024 13:10:06 +0000 (14:10 +0100)
commitcda7275ef5d5e49fb2ea2373ea3b1ba63fc927c3
tree86d90ebf653f58f6c8dc314df2196c85ca771800
parent3372a2ea000dbfa29a1fcb5643e7e259603ec331
MEDIUM: queue: Handle the race condition between queue and dequeue differently

There is a small race condition, where a server would check if there is
something left in the proxy queue, and adding something to the proxy
queue. If the server checks just before the stream is added to the queue,
and it no longer has any stream to deal with, then nothing will take
care of the stream, that may stay in the queue forever.
This was worked around with commit 5541d4995d, by checking for that exact
condition after adding the stream to the queue, and trying again to get
a server assigned if it is detected.
That fix lead to multiple infinite loops, that got fixed, but it is not
unlikely that it could happen again. So let's fix the initial problem
differently : a single server may mark itself as ready, and it removes
itself once used. The principle is that when we discover that the just
queued stream is alone with no active request anywhere ot dequeue it,
instead of rebalancing it, it will be assigned to that current "ready"
server that is available to handle it. The extra cost of the atomic ops
is negligible since the situation is super rare.
include/haproxy/proxy-t.h
src/backend.c
src/queue.c
src/server.c