BUG/MEDIUM: thread: use pthread_self() not ha_pthread[tid] in set_affinity
authorWilly Tarreau <w@1wt.eu>
Wed, 12 Mar 2025 14:54:36 +0000 (15:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Mar 2025 15:23:59 +0000 (16:23 +0100)
commitc056c7fadd8cd435c1155e5a4dba90fd50d4ba2e
tree529f7d9a59c799172d0a603c5277f09b6c42d40b
parent08ba5eb272fd841107a2fb79e62c8ee91dd9c852
BUG/MEDIUM: thread: use pthread_self() not ha_pthread[tid] in set_affinity

A bug was uncovered by the work on NUMA. It only triggers in the CI
with libmusl due to a race condition. What happens is that the call
to set_thread_cpu_affinity() is done very early in the polling loop,
and that it relies on ha_pthread[tid] instead of pthread_self(). The
problem is that ha_pthread[tid] is only set by the return from
pthread_create(), which might happen later depending on the number of
CPUs available to run the starting thread.

Let's just use pthread_self() here. ha_pthread[] is only used to send
signals between threads, there's no point in using it here.

This can be backported to 2.6.

(cherry picked from commit 12383fd9f5b3614dbffec6260b82659c3c5fd0df)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 77494a9104e6d3ad5d8ca24f2fb343ab2e4b1c13)
Signed-off-by: Willy Tarreau <w@1wt.eu>
src/thread.c