MINOR: pools: preset the allocation failure rate to 1% with -dMfail

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.
This commit is contained in:
Willy Tarreau 2023-03-21 09:24:53 +01:00
parent 69869e6354
commit 0c4348c982
3 changed files with 11 additions and 2 deletions

View 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

View 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

View 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;
}
}