]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse: simulate long configuration parsing with force-cfg-parser-pause
authorWilliam Lallemand <wlallemand@haproxy.com>
Fri, 11 Oct 2024 15:38:46 +0000 (17:38 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Fri, 11 Oct 2024 15:40:37 +0000 (17:40 +0200)
This command is pausing the configuration parser for <timeout>
milliseconds. This is useful for development or for testing timeouts of
init scripts, particularly to simulate a very long reload. It requires
the expose-experimental-directives to be set.

doc/configuration.txt
src/cfgparse-global.c

index a1460be70efc59457ac346d9aee623519ef73734..1c5cc9337586bc870df7f1beade363b19c3e4334 100644 (file)
@@ -4304,6 +4304,23 @@ anonkey <key>
   from the CLI command "set anon global-key". See also command line argument
   "-dC" in the management manual.
 
+force-cfg-parser-pause <timeout>
+  This command is pausing the configuration parser for <timeout> milliseconds.
+  This is useful for development or for testing timeouts of init scripts,
+  particularly to simulate a very long reload.
+  It requires the expose-experimental-directives to be set.
+
+  <timeout> is the timeout value specified in milliseconds by default, but
+              can be in any other unit if the number is suffixed by the unit,
+              as explained at the top of this document.
+
+  Example:
+
+    global
+        expose-experimental-directives
+        force-cfg-parser-pause 10s
+
+
 quick-exit
   This speeds up the old process exit upon reload by skipping the releasing of
   memory objects and listeners, since all of these are reclaimed by the
index 12cac06e3c0097938d06be89454fe44731673769..5be150f5fa8a041d164fbca5328ca2523117a500 100644 (file)
@@ -1474,8 +1474,51 @@ static int cfg_parse_global_env_opts(char **args, int section_type,
        return 0;
 }
 
+static int cfg_parse_global_parser_pause(char **args, int section_type,
+                                         struct proxy *curpx, const struct proxy *defpx,
+                                         const char *file, int line, char **err)
+{
+       unsigned int ms = 0;
+       const char *res;
+
+       if (*(args[1]) == 0) {
+               memprintf(err, "'%s' expects a timer value between 0 and 65535 ms.", args[0]);
+               return -1;
+       }
+
+       if (too_many_args(1, args, err, NULL))
+               return -1;
+
+
+       res = parse_time_err(args[1], &ms, TIME_UNIT_MS);
+       if (res == PARSE_TIME_OVER) {
+               memprintf(err, "timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.",
+                               args[1], args[0]);
+               return -1;
+       }
+       else if (res == PARSE_TIME_UNDER) {
+               memprintf(err, "timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.",
+                               args[1], args[0]);
+               return -1;
+       }
+       else if (res) {
+               memprintf(err, "unexpected character '%c' in argument to <%s>.", *res, args[0]);
+               return -1;
+       }
+
+       if (ms > 65535) {
+               memprintf(err, "'%s' expects a timer value between 0 and 65535 ms.", args[0]);
+               return -1;
+       }
+
+       usleep(ms * 1000);
+
+       return 0;
+}
+
 static struct cfg_kw_list cfg_kws = {ILH, {
        { CFG_GLOBAL, "prealloc-fd", cfg_parse_prealloc_fd },
+       { CFG_GLOBAL, "force-cfg-parser-pause", cfg_parse_global_parser_pause, KWF_EXPERIMENTAL },
        { CFG_GLOBAL, "harden.reject-privileged-ports.tcp",  cfg_parse_reject_privileged_ports },
        { CFG_GLOBAL, "harden.reject-privileged-ports.quic", cfg_parse_reject_privileged_ports },
        { CFG_GLOBAL, "master-worker", cfg_parse_global_master_worker },