MINOR: listener: make sure to avoid ABA updates in per-thread index
authorWilly Tarreau <w@1wt.eu>
Thu, 20 Apr 2023 14:52:21 +0000 (16:52 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 21 Apr 2023 15:41:26 +0000 (17:41 +0200)
commitff18504d7322ee262caa257dc0241afc9d8493c4
treeca0e640582ede4e32379bc994f58045769e291ca
parent77e33509c8603b67340f9d754b16b1fbaec7ac15
MINOR: listener: make sure to avoid ABA updates in per-thread index

One limitation of the current thread index mechanism is that if the
values are assigned multiple times to the same thread and the index
loops, it can match again the old value, which will not prevent a
competing thread from finishing its CAS and assigning traffic to a
thread that's not the optimal one. The probability is low but the
solution is simple enough and consists in implementing an update
counter in the high bits of the index to force a mismatch in this
case (assuming we don't try to cover for extremely unlikely cases
where the update counter loops while the index remains equal). So
let's do that. In order to improve the situation a little bit, we
now set the index to a ulong so that in 32 bits we have 8 bits of
counter and in 64 bits we have 40 bits.
include/haproxy/listener-t.h
src/listener.c