MEDIUM: lua: Use a per-thread counter to track some non-reentrant parts of lua
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 19 Mar 2021 14:16:28 +0000 (15:16 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 23 Mar 2021 08:24:50 +0000 (09:24 +0100)
commit08aec89f712409b032c490165b9f0fb0e9572164
treeb557605fccf82dd2442939f17a3558d314119cf5
parent2af5bc482c4cf6ff71f633bf6b78f31bc4637d79
MEDIUM: lua: Use a per-thread counter to track some non-reentrant parts of lua

Some parts of the Lua are non-reentrant. We must be sure to carefully track
these parts to not dump the lua stack when it is interrupted inside such
parts. For now, we only identified the custom lua allocator. If the thread
is interrupted during the memory allocation, we must not try to print the
lua stack wich also allocate memory. Indeed, realloc() is not
async-signal-safe.

In this patch we introduce a thread-local counter. It is incremented before
entering in a non-reentrant part and decremented when exiting. It is only
performed in hlua_alloc() for now.

(cherry picked from commit a61789a1d62fd71c751189faf5371740dd375f33)
[wt: the code uses malloc/realloc/free depending on the inputs in 2.3,
 let's place the counter around these 3 calls]
Signed-off-by: Willy Tarreau <w@1wt.eu>
include/haproxy/hlua.h
src/hlua.c