From: Willy Tarreau Date: Fri, 20 Nov 2026 18:23:26 +0000 (+0100) Subject: MEDIUM: config: emit warnings when changing bufsize after other sections X-Git-Url: https://git.kaiwu.me/http/ngx_http_auth_basic_module.html?a=commitdiff_plain;h=2b7dea07a90b52e075ff49856471613621f5efbe;p=haproxy.git MEDIUM: config: emit warnings when changing bufsize after other sections Long ago we emitted a diag when a global section is placed after some non-global sections, but that's not sufficient because it's even possible to change tune.bufsize (even shrink it) and face problems such as return directives or errorfiles loaded with a larger value not being able to be delivered. Let's now emit warnings when the value changes, explaining the risks, discourage from doing so, and do that as well for tune.maxrewrite and tune.http.maxhdr, which also impacts the ability to build HTTP replies on the fly. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index c5ffbd4d2..9c5e2f5f6 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -4522,7 +4522,10 @@ tune.bufsize HTTP response is larger than this size, HAProxy will return an HTTP 502 (Bad Gateway) error. Note that the value set using this parameter will automatically be rounded up to the next multiple of 8 on 32-bit machines and - 16 on 64-bit machines. See also: tune.bufsize.large, tune.bufsize.small. + 16 on 64-bit machines. Since this value is already used while parsing + proxies (e.g. to load "errorfile" and "http-return" payloads), it must be set + in a global section placed before any other section, otherwise a warning is + emitted. See also: tune.bufsize.large, tune.bufsize.small. tune.bufsize.large Sets the size in bytes for large buffers. By defaults, support for large @@ -5111,7 +5114,10 @@ tune.http.maxhdr uses the same limit. It can be useful to push this limit further to temporarily allow a buggy application to work by the time it gets fixed. The accepted range is 1..32767. Keep in mind that each new header consumes 32bits - of memory for each stream, so don't push this limit too high. + of memory for each stream, so don't push this limit too high. Since this + value is already used while parsing proxies (e.g. to load "errorfile" + payloads), it must be set in a global section placed before any other + section, otherwise a warning is emitted. Note that HTTP/1.1 is a text protocol, so there is no special limit when the message is sent. The limit during the message parsing is sufficient. HTTP/2 @@ -5403,7 +5409,9 @@ tune.maxrewrite to already large requests or to POST requests. It is generally wise to set it to about 1024. It is automatically readjusted to half of bufsize if it is larger than that. This means you don't have to worry about it when changing - bufsize. + bufsize. Since this value is already used while parsing proxies (e.g. to + check "http-return" payloads), it must be set in a global section placed + before any other section, otherwise a warning is emitted. tune.max-rules-at-once Sets the maximum number of rules that can be evaluated at once in ruleset diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c index 433bafa66..e80b9c504 100644 --- a/src/cfgparse-global.c +++ b/src/cfgparse-global.c @@ -414,6 +414,8 @@ static int cfg_parse_global_tune_opts(char **args, int section_type, return 0; } else if (strcmp(args[0], "tune.bufsize") == 0) { + uint old_bufsize = global.tune.bufsize; + if (*(args[1]) == 0) { memprintf(err, "'%s' expects an integer argument", args[0]); return -1; @@ -435,6 +437,18 @@ static int cfg_parse_global_tune_opts(char **args, int section_type, return -1; } + if (non_global_section_parsed) { + if (global.tune.bufsize < old_bufsize) + memprintf(err, "Shrinking '%s' after a non-global section will lead to runtime" + " failures particularly in HTTP. As a general rule, only change this" + " setting once and in the very first global section.", args[0]); + else + memprintf(err, "Changing '%s' after a non-global section will not affect parts" + " that were already parsed with the earlier value. As a general rule," + " only change this setting once and in the very first global section.", + args[0]); + return 1; + } return 0; } else if (strcmp(args[0], "tune.maxrewrite") == 0) { @@ -448,6 +462,12 @@ static int cfg_parse_global_tune_opts(char **args, int section_type, return -1; } + if (non_global_section_parsed) { + memprintf(err, "Changing '%s' after a non-global section will lead to runtime" + " failures particularly in HTTP. As a general rule, only change this" + " setting once and in the very first global section.", args[0]); + return 1; + } return 0; } else if (strcmp(args[0], "tune.idletimer") == 0) { @@ -622,6 +642,12 @@ static int cfg_parse_global_tune_opts(char **args, int section_type, return -1; } + if (non_global_section_parsed) { + memprintf(err, "Changing '%s' after a non-global section will lead to runtime" + " failures particularly in HTTP. As a general rule, only change this" + " setting once and in the very first global section.", args[0]); + return 1; + } return 0; } else if (strcmp(args[0], "tune.comp.maxlevel") == 0) {