MINOR: cfgparse: simulate long configuration parsing with force-cfg-parser-pause

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.
This commit is contained in:
William Lallemand 2024-10-11 17:38:46 +02:00
parent 232083c3e5
commit edf85a1d76
2 changed files with 60 additions and 0 deletions

View File

@ -4304,6 +4304,23 @@ anonkey <key>
from the CLI command "set anon global-key". See also command line argument from the CLI command "set anon global-key". See also command line argument
"-dC" in the management manual. "-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 quick-exit
This speeds up the old process exit upon reload by skipping the releasing of 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 memory objects and listeners, since all of these are reclaimed by the

View File

@ -1474,8 +1474,51 @@ static int cfg_parse_global_env_opts(char **args, int section_type,
return 0; 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, { static struct cfg_kw_list cfg_kws = {ILH, {
{ CFG_GLOBAL, "prealloc-fd", cfg_parse_prealloc_fd }, { 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.tcp", cfg_parse_reject_privileged_ports },
{ CFG_GLOBAL, "harden.reject-privileged-ports.quic", 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 }, { CFG_GLOBAL, "master-worker", cfg_parse_global_master_worker },