]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: lua: Protect the common Lua state during a runtime filter deinit
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 7 Oct 2026 15:03:30 +0000 (17:03 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 9 Oct 2026 14:17:36 +0000 (16:17 +0200)
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.

src/hlua.c

index 66f794c820eca29f4e9807fe45136776eacd37c9..255dccf0554bd0c41c159bc8d16f9856116c4c08 100644 (file)
@@ -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)