]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua: ignore "tune.lua.bool-sample-conversion" if set after "lua-load"
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 2 May 2025 11:56:08 +0000 (13:56 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 2 May 2025 12:38:37 +0000 (14:38 +0200)
tune.lua.bool-sample-conversion must be set before any lua-load or
lua-load-per-thread is used for it to be considered. Indeed, lua-load
directives are parsed on the fly and will cause some parts of the scripts
to be executed during init already (script body/init contexts).

As such, we cannot afford to have "tune.lua.bool-sample-conversion" set
after some Lua code was loaded, because it would mean that the setting
would be handled differently for Lua's code executed during or after
config parsing.

To avoid ambiguities, the documentation now states that the setting must
be set before any lua-load(-per-thread) directive, and if the setting
is met after some Lua was already loaded, the directive is ignored and
a warning informs about that.

It should fix GH #2957

It may be backported with 29b6d8af16 ("MINOR: hlua: rename
"tune.lua.preserve-smp-bool" to "tune.lua.bool-sample-conversion"")

doc/configuration.txt
src/hlua.c

index 0d87151b72816d20bb04096eff618a0a98f52aed..9abe29476c6b3ee987f7009cadbf1573cee7cffc 100644 (file)
@@ -4085,6 +4085,9 @@ tune.lua.bool-sample-conversion { normal | pre-3.1-bug }
   behavior. It is recommended to set this option to "normal" after ensuring
   that in-use Lua scripts are properly handling bool haproxy samples as booleans.
 
+  This setting must be set before any "lua-load" or "lua-load-per-thread"
+  directive for it to be considered, else it is ignored.
+
 tune.lua.burst-timeout <timeout>
   The "burst" execution timeout applies to any Lua handler. If the handler
   fails to finish or yield before timeout is reached, it will be aborted to
index 767406a43b53e7394e7de465903abb00d54f794c..cb18132ae5ad63a8901da3e12942a86068f472a4 100644 (file)
@@ -84,6 +84,9 @@ enum hlua_log_opt {
 /* default log options, made of flags in hlua_log_opt */
 static uint hlua_log_opts = HLUA_LOG_LOGGERS_ON | HLUA_LOG_STDERR_AUTO;
 
+/* set to 1 once some lua was loaded already */
+static uint8_t hlua_loaded = 0;
+
 #define HLUA_BOOL_SAMPLE_CONVERSION_UNK     0x0
 #define HLUA_BOOL_SAMPLE_CONVERSION_NORMAL  0x1
 #define HLUA_BOOL_SAMPLE_CONVERSION_BUG     0X2
@@ -13084,17 +13087,28 @@ static int hlua_cfg_parse_bool_sample_conversion(char **args, int section_type,
                                                  const struct proxy *defpx, const char *file, int line,
                                                  char **err)
 {
+       uint8_t set;
+
        if (too_many_args(1, args, err, NULL))
                return -1;
 
        if (strcmp(args[1], "normal") == 0)
-               hlua_bool_sample_conversion = HLUA_BOOL_SAMPLE_CONVERSION_NORMAL;
+               set = HLUA_BOOL_SAMPLE_CONVERSION_NORMAL;
        else if (strcmp(args[1], "pre-3.1-bug") == 0)
-               hlua_bool_sample_conversion = HLUA_BOOL_SAMPLE_CONVERSION_BUG;
+               set = HLUA_BOOL_SAMPLE_CONVERSION_BUG;
        else {
                memprintf(err, "'%s' expects either 'normal' or 'pre-3.1-bug' but got '%s'.", args[0], args[1]);
                return -1;
        }
+
+       if (hlua_loaded)
+               ha_warning("parsing [%s:%d] : %s", file, line, "ignored as some Lua was loaded "
+                          "already. \"tune.lua.bool-sample-conversion\" must be set before "
+                          "any \"lua-load\" or \"lua-load-per-thread\" directive for it to be "
+                          "considered.\n");
+       else
+               hlua_bool_sample_conversion = set;
+
        return 0;
 }
 
@@ -13118,6 +13132,8 @@ static int hlua_load_state(char **args, lua_State *L, char **err)
        int nargs;
 
        if (ONLY_ONCE()) {
+               hlua_loaded = 1;
+
                /* we know we get there if "lua-load" or "lua-load-per-thread" was
                 * used in the config
                 */
@@ -13128,7 +13144,8 @@ static int hlua_load_state(char **args, lua_State *L, char **err)
                         */
                        ha_warning("hlua: please set \"tune.lua.bool-sample-conversion\" tunable "
                                   "to either \"normal\" or \"pre-3.1-bug\" explicitly to avoid "
-                                  "ambiguities. Defaulting to \"pre-3.1-bug\".\n");
+                                  "ambiguities. This must be set before any \"lua-load\" or "
+                                  "\"lua-load-per-thread\" directive. Defaulting to \"pre-3.1-bug\".\n");
                }
        }