]> git.kaiwu.me - haproxy.git/commitdiff
MEDIUM: config: emit warnings when changing bufsize after other sections
authorWilly Tarreau <w@1wt.eu>
Fri, 20 Nov 2026 18:23:26 +0000 (19:23 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 Nov 2026 18:25:53 +0000 (19:25 +0100)
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.

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

index c5ffbd4d212f0a83f0dbfd5bd963944d9ae91cc5..9c5e2f5f6326ec19d74f58e06e05e2092b0a43fd 100644 (file)
@@ -4522,7 +4522,10 @@ tune.bufsize <size>
   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 <size>
   Sets the size in bytes for large buffers. By defaults, support for large
@@ -5111,7 +5114,10 @@ tune.http.maxhdr <number>
   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 <number>
   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 <number>
   Sets the maximum number of rules that can be evaluated at once in ruleset
index 433bafa661ab3902905b190c51948e766afb9bf8..e80b9c5042c2375ee93c8b63d2df7764d1357ece 100644 (file)
@@ -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) {