BUG/MINOR: guid/server: ensure thread-safety on GUID insert/delete
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 7 Nov 2024 10:08:40 +0000 (11:08 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 13 Nov 2024 09:57:15 +0000 (10:57 +0100)
commit85fa6d5b77645ecdfaf684c61874032c0545a0d6
tree40dfc0d9f9f884df3c0691e13fd95c7408ab7aa3
parentd68329f01423627a738c8b01898fe72515e3c986
BUG/MINOR: guid/server: ensure thread-safety on GUID insert/delete

Since 3.0, it is possible to assign a GUID to proxies, listeners and
servers. These objects are stored in a global tree guid_tree.

Proxies and listeners are static. However, servers may be added or
deleted at runtime, which imply that guid_tree must be protected. Fix
this by declaring a read-write lock to protect tree access.

For now, only guid_insert() and guid_remove() are protected using a
write lock. Outside of these, GUID tree is not accessed at runtime. If
server CLI commands are extended to support GUID as server identifier,
lookup operation should be extended with a read lock protection.

Note that during stat-file preloading, GUID tree is accessed for lookup.
However, as it is performed on startup which is single threaded, there
is no need for lock here. A BUG_ON() has been added to ensure this
precondition remains true.

This bug could caused a segfault when using dynamic servers with GUID.
However, it was never reproduced for now.

This must be backported up to 3.0. To avoid a conflict issue, the
previous cleanup patch can be merged before it.

(cherry picked from commit 8e0e7d9d1af5b2dfec2e625d2c19dd034c36eb04)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
include/haproxy/guid.h
include/haproxy/thread-t.h
src/guid.c
src/thread.c