Skip to content

fix(cli): reject nan, inf, overflow and empty --retry-backoff-factor - #692

Merged
fcostaoliveira merged 1 commit into
masterfrom
fix-687-retry-backoff-parse
Oct 16, 2026
Merged

fcostaoliveira merged 1 commit into
masterfrom
fix-687-retry-backoff-parse

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Decision: --retry-backoff-factor now accepts exactly what --reconnect-backoff-factor accepts since #668: a finite, representable number >= 0. 0 (constant backoff, the default) and -0.0 stay accepted. Values that were silently accepted before (nan, inf, 1e9999, 1e-9999, "") now exit 2 with a parser error. Finite subnormal values that glibc's strtod reports with ERANGE (e.g. 1e-310) are rejected too, the same as --reconnect-backoff-factor since #668. Normal tiny values such as 1e-300 remain accepted.

Problem

--retry-backoff-factor accepted nan, -nan, inf, +inf, infinity, 1e9999, 1e-9999, -1e-9999 and an empty string without error:

  • nan: the retry_backoff_factor > 0.0 guard in shard_connection.cpp is false for NaN, so the backoff silently stayed constant.
  • inf / 1e9999: the delay jumped straight to MEMTIER_BACKOFF_CAP_MS after the first retry.
  • "": strtod parsed nothing and returned 0, which silently meant "no exponential backoff".
  • The JSON configuration block recorded "retry_backoff_factor": null for nan/inf.

Root cause

In config_parse_args(), the o_retry_backoff_factor case checked only < 0.0 and *endptr != '\0'. It had no endptr == optarg check, no errno reset or ERANGE check, and no std::isfinite check. #668 added these checks for the sibling --reconnect-backoff-factor only.

Fix

  • New static bool parse_backoff_factor(const char *s, double *out) in memtier_benchmark.cpp, with the Accept explicit zero reconnect backoff factor #668 validation (errno = 0; reject endptr == s, trailing characters, ERANGE, non-finite, < 0). Both --reconnect-backoff-factor and --retry-backoff-factor use it, so the two flags cannot drift apart again. The reconnect behaviour and its message are unchanged.
  • The retry error message keeps its wording style: error: retry-backoff-factor must be a finite, representable number >= 0 (0 = no exponential, constant backoff).
  • --help and the man page are unchanged, because the documented meaning and default did not change.

Tests

New tests/test_cli_validation_retry_backoff.py, modelled on test_cli_validation_reconnect_backoff.py:

  • default, 0 and 2 complete a --retry-on-error benchmark, and the JSON records the requested factor.
  • 0, -0.0, 0.5, 1, 2 and 1e308 parse (--version exits 0).
  • 19 invalid values exit 2 with a retry-backoff-factor diagnostic. The list is the same one used in the reconnect test.
  • An errno carried over from an earlier option's strtoul overflow does not reject a valid factor.

The new file runs in the same asan/tsan/ubsan TLS CLI selections as test_cli_validation_reconnect_backoff.py.

Local evidence (standalone Redis, RLTest existing-env):

binary runs result
origin/master 969c4de 6 6/6 fail test_retry_backoff_invalid_values_rejected. These 10 values slip through: nan NaN -nan inf +inf infinity 1e9999 1e-9999 -1e-9999 "". The other 5 tests pass.
this branch 6 6/6 pass all 16 tests (6 retry + 10 reconnect). No flakes.

Repro on master: for v in nan inf 1e9999 ""; do memtier_benchmark --retry-backoff-factor="$v" --version >/dev/null 2>&1; echo "$v rc=$?"; done prints rc=0 for every value. With this branch, every value prints rc=2.

Fixes #687

Affected versions

2.4.0 through 2.5.2 (latest) and master.

🤖 Generated with Claude Code

--retry-backoff-factor only checked `< 0.0` and trailing characters, so
nan, -nan, inf, infinity, 1e9999, 1e-9999 and an empty string were all
accepted. NaN silently disabled the exponential backoff (the `> 0.0`
guard in shard_connection.cpp is false for NaN), inf/overflow jumped the
delay straight to the cap, the empty string silently meant 0, and the
JSON configuration block recorded null for nan/inf.

#668 already fixed the same problem for --reconnect-backoff-factor. Move
that validation (errno reset, endptr == optarg, ERANGE, isfinite, >= 0)
into one parse_backoff_factor() helper and use it for both flags so they
cannot drift apart again. 0 (constant backoff) stays accepted.

Add tests/test_cli_validation_retry_backoff.py, mirroring the reconnect
test, and run it in the same asan/tsan/ubsan CLI selections.

Fixes #687

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--retry-backoff-factor accepts nan, inf, overflow and an empty value

1 participant