BUG/MEDIUM: lb: Always lock the server when calling server_{take,drop}_conn
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 16 Oct 2020 14:27:17 +0000 (16:27 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 19 Oct 2020 06:42:47 +0000 (08:42 +0200)
commitec879982c223757d9c192ee7ea20deb1c890267e
tree317cacaf8ca15e2361e3dbbca0f2a88894eb4af1
parent259b94cebda755276f1becc25d6142ec5a58ad84
BUG/MEDIUM: lb: Always lock the server when calling server_{take,drop}_conn

The server lock must be held when server_take_conn() and server_drop_conn()
lbprm callback functions are called. It is a documented prerequisite but it is
not always performed. It only affects leastconn and fas lb algorithm. Others
don't use these callback functions.

A race condition on the next pending effecive weight (next_eweight) may be
encountered with the leastconn lb algorithm. An agent check may set it to 0
while fwlc_srv_reposition() is called. The server is locked during the
next_eweight update. But because the server lock is not acquired when
fwlc_srv_reposition() is called, we may use it to recompute the server key,
leading to a division by 0.

This patch must be backported as far as 1.8.

(cherry picked from commit 26a52af642c3fcfd6a637aef019b78147c05e126)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit e50dd9f3dd622937e0b7bb4cbe7067c50e9a1f13)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/backend.c
src/stream.c