BUG/MINOR: haproxy/threads: close a possible race in soft-stop detection
authorWilly Tarreau <w@1wt.eu>
Mon, 23 Mar 2020 08:27:28 +0000 (09:27 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Mar 2020 14:52:58 +0000 (16:52 +0200)
commite04beb23b0d1e6abbb94481612e3a7439f9172a5
tree4b3024ed6475302f98732414ee67482c8e33467d
parentc8e159762a8c73e21d7b7ed32a0c76370c714152
BUG/MINOR: haproxy/threads: close a possible race in soft-stop detection

Commit 4b3f27b ("BUG/MINOR: haproxy/threads: try to make all threads
leave together") improved the soft-stop synchronization but it left a
small race open because it looks at tasks_run_queue, which can drop
to zero then back to one while another thread picks the task from the
run queue to insert it into the tasklet_list. The risk is very low but
not null. In addition the condition didn't consider the possible presence
of signals in the queue.

This patch moves the stopping detection just after the "wake" calculation
which already takes care of the various queues' sizes and signals. It
avoids needlessly duplicating these tests.

The bug was discovered during a code review but will probably never be
observed. This fix may be backported to 2.1 and 2.0 along with the commit
above.

(cherry picked from commit 4f46a354e67f4a7781570f6f4e17738eeca9d5ac)
[wt: context adjustment around call to wake_expired_tasks()]
Signed-off-by: Willy Tarreau <w@1wt.eu>
src/haproxy.c