From: Christopher Faulet Date: Wed, 7 Oct 2026 15:03:30 +0000 (+0200) Subject: MINOR: lua: Protect the common Lua state during a runtime filter deinit X-Git-Tag: v3.5-dev9~48 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=d26aff11b5dcc9c17b44f8b42436b159a1f3c3c9;p=haproxy.git MINOR: lua: Protect the common Lua state during a runtime filter deinit hlua_filter_deinit_per_thread() releases the filter reference from the shared Lua state without taking the global lock. This is fine during the startup and the shutdown, where it is the only user of the state, but the proxies dynamically created with "add backend" are destroyed at runtime with "del backend", with their filter instances finalized: their deinit callback may then run while other threads execute Lua code on the shared state. Take the global lock when releasing the reference of the common state, as all the other runtime users of this state do. --- diff --git a/src/hlua.c b/src/hlua.c index 66f794c82..255dccf05 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -11994,7 +11994,18 @@ static void hlua_filter_deinit_per_thread(struct proxy *px, struct flt_conf *fco state_id = reg_flt_to_stack_id(conf->reg); L = hlua_states[state_id]; + + /* The common state is shared by all the threads, which may be running + * Lua code when a dynamically created proxy is destroyed at runtime: + * the reference must be released under the global lock. This is + * uncontended during the startup and the shutdown, where this also + * runs. + */ + if (!state_id) + lua_take_global_lock(); hlua_unref(L, conf->ref[state_id]); + if (!state_id) + lua_drop_global_lock(); } static int hlua_filter_init(struct proxy *px, struct flt_conf *fconf)