]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: preset the allocation failure rate to 1% with -dMfail
authorWilly Tarreau <w@1wt.eu>
Tue, 21 Mar 2023 08:24:53 +0000 (09:24 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 21 Mar 2023 08:26:55 +0000 (09:26 +0100)
Using -dMfail alone does nothing unless tune.fail-alloc is set, which
renders it pretty useless as-is, and is not intuitive. Let's change
this so that the filure rate is preset to 1% when the option is set on
the command line. This allows to inject failures without having to edit
the configuration.

doc/configuration.txt
doc/management.txt
src/pool.c

index 446d1a2d849391b953f1860f6a00289dabbf4dde..0c22b8265fe20718b4cd95c968e7bb9f951f94bf 100644 (file)
@@ -2865,7 +2865,9 @@ tune.fail-alloc
   If compiled with DEBUG_FAIL_ALLOC or started with "-dMfail", gives the
   percentage of chances an allocation attempt fails. Must be between 0 (no
   failure) and 100 (no success). This is useful to debug and make sure memory
-  failures are handled gracefully.
+  failures are handled gracefully. When not set, the ratio is 0. However the
+  command-line "-dMfail" option automatically sets it to 1% failure rate so that
+  it is not necessary to change the configuration for testing.
 
 tune.fd.edge-triggered { on | off }  [ EXPERIMENTAL ]
   Enables ('on') or disables ('off') the edge-triggered polling mode for FDs
index 94451b524e1b9c3e9297a36531cf6bd48cb643e3..96bd30c3d98afa4b7112eaaa224143c574d5b742 100644 (file)
@@ -290,7 +290,8 @@ list of options is :
       - fail / no-fail:
         This enables randomly failing memory allocations, in conjunction with
         the global "tune.fail-alloc" setting. This is used to detect missing
-        error checks in the code.
+        error checks in the code. Setting the option presets the ratio to 1%
+        failure rate.
 
       - no-merge / merge:
         By default, pools of very similar sizes are merged, resulting in more
index 4ea8d812703750123957fc5cce8b8a6459dabbd1..345681a0c33f6c5301068f3bdea94c95a1f4befb 100644 (file)
@@ -1080,10 +1080,16 @@ int pool_parse_debugging(const char *str, char **err)
                                 */
                                if (dbg_options[v].flg == POOL_DBG_UAF)
                                        new_dbg |= POOL_DBG_NO_CACHE;
+                               /* fail should preset the tune.fail-alloc ratio to 1%  */
+                               if (dbg_options[v].flg == POOL_DBG_FAIL_ALLOC)
+                                       mem_fail_rate = 1;
                                break;
                        }
                        else if (isteq(feat, ist(dbg_options[v].clr))) {
                                new_dbg &= ~dbg_options[v].flg;
+                               /* no-fail should reset the tune.fail-alloc ratio */
+                               if (dbg_options[v].flg == POOL_DBG_FAIL_ALLOC)
+                                       mem_fail_rate = 0;
                                break;
                        }
                }