Repository navigation
fix(cli): reject nan, inf, overflow and empty --retry-backoff-factor - #692
Merged
Merged
Conversation
--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]>
This was referenced Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Decision:
--retry-backoff-factornow accepts exactly what--reconnect-backoff-factoraccepts since #668: a finite, representable number >= 0.0(constant backoff, the default) and-0.0stay accepted. Values that were silently accepted before (nan,inf,1e9999,1e-9999,"") now exit 2 with a parser error. Finite subnormal values that glibc'sstrtodreports withERANGE(e.g.1e-310) are rejected too, the same as--reconnect-backoff-factorsince #668. Normal tiny values such as1e-300remain accepted.Problem
--retry-backoff-factoracceptednan,-nan,inf,+inf,infinity,1e9999,1e-9999,-1e-9999and an empty string without error:nan: theretry_backoff_factor > 0.0guard inshard_connection.cppis false for NaN, so the backoff silently stayed constant.inf/1e9999: the delay jumped straight toMEMTIER_BACKOFF_CAP_MSafter the first retry."":strtodparsed nothing and returned 0, which silently meant "no exponential backoff".configurationblock recorded"retry_backoff_factor": nullfor nan/inf.Root cause
In
config_parse_args(), theo_retry_backoff_factorcase checked only< 0.0and*endptr != '\0'. It had noendptr == optargcheck, noerrnoreset orERANGEcheck, and nostd::isfinitecheck. #668 added these checks for the sibling--reconnect-backoff-factoronly.Fix
static bool parse_backoff_factor(const char *s, double *out)inmemtier_benchmark.cpp, with the Accept explicit zero reconnect backoff factor #668 validation (errno = 0; rejectendptr == s, trailing characters,ERANGE, non-finite,< 0). Both--reconnect-backoff-factorand--retry-backoff-factoruse it, so the two flags cannot drift apart again. The reconnect behaviour and its message are unchanged.error: retry-backoff-factor must be a finite, representable number >= 0 (0 = no exponential, constant backoff).--helpand the man page are unchanged, because the documented meaning and default did not change.Tests
New
tests/test_cli_validation_retry_backoff.py, modelled ontest_cli_validation_reconnect_backoff.py:default,0and2complete a--retry-on-errorbenchmark, and the JSON records the requested factor.0,-0.0,0.5,1,2and1e308parse (--versionexits 0).retry-backoff-factordiagnostic. The list is the same one used in the reconnect test.errnocarried over from an earlier option'sstrtouloverflow 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):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.Repro on master:
for v in nan inf 1e9999 ""; do memtier_benchmark --retry-backoff-factor="$v" --version >/dev/null 2>&1; echo "$v rc=$?"; doneprints 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