Skip to content

Accept explicit zero reconnect backoff factor - #668

Merged
fcostaoliveira merged 3 commits into
masterfrom
fix/reconnect-backoff-zero-658
Oct 15, 2026
Merged

fcostaoliveira merged 3 commits into
masterfrom
fix/reconnect-backoff-zero-658

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

--reconnect-backoff-factor=0 previously exited with an argument error even though zero is the documented default. Accept explicit zero so wrappers can pass the default value directly.

Require a fully parsed, finite, nonnegative factor and reject out-of-range conversions, including underflow that could otherwise turn a negative input into zero. Positive fractional factors remain supported. Clarify the existing behavior in --help and the man page: zero keeps the one-second delay, while positive factors multiply it. Reconnect scheduling is unchanged. This intentionally tightens validation for previously accepted infinity/overflow inputs and underflowing positive values; they now produce an argument error.

Validation:

  • New regression suite: master passes 5/8 tests; the fix passes 8/8 under ASan on both plaintext and TLS. Seven acceptance cases validate actual benchmark JSON; invalid-input coverage checks 19 values and option-specific errors.
  • Existing reconnect suite: 10 passed, 3 cluster-only skips. make check: 6 passed. Formatting and staged C++ hook passed.
  • Added the new test file to explicit ASan, TSan, and UBSan TLS selections.
  • test_reconnect_backoff_zero_keeps_one_second_delay pins the documented zero behaviour: against a closed port, every logged reconnect delay is 1.00 s (fails with 0.00 s if the > 0.0 guard is changed to >= 0.0).
  • The zero/fractional semantics are documented in --help, so make rebuild-man keeps them; the man page matches help2man output. 1e308 remains the finite replacement for the previously accepted inf.
  • CI step timeouts are left to ci: run standalone test cells with PARALLELISM=2 and raise the step limit to 40 min #683 (CI: standalone TLS test jobs now take ~25 min and hit the 25-minute "Run tests" limit #679).

Fixes #658.


Note

Low Risk
Narrow CLI parsing and documentation change with regression tests; previously accepted non-finite or overflow inputs now error at startup.

Overview
Fixes --reconnect-backoff-factor=0 being rejected at parse time even though zero is the documented default. Validation now accepts any finite, nonnegative value (including explicit 0 and fractional factors) and rejects garbage, negatives, NaN/inf, and overflow/underflow from strtod, with errno cleared so a prior option’s parse error cannot spuriously fail this flag.

Help and memtier_benchmark.1 now state that zero keeps a 1 s reconnect delay and positive values multiply it per attempt. A new test_cli_validation_reconnect_backoff.py suite covers successful runs, invalid inputs, and the 1.00 s delay behavior against a closed port. ASan/TSan/UBSan TLS matrix cells include the new test file.

Reviewed by Cursor Bugbot for commit 19658b8. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🤖 Automated first-pass review — a human maintainer's review is still required before merge.

Thanks for this. The core fix looks right, and the closed-port test that pins every delay at 1.00 s for factor 0 is a good way to lock down the documented behaviour. A few questions:

  1. Rejecting inf and overflow. The description says this break is intentional, but I'm not sure it's needed. Both reconnect paths in shard_connection.cpp (~1783 and ~1904) multiply the delay and then clamp it to MEMTIER_BACKOFF_CAP_SEC. So --reconnect-backoff-factor=inf (or 1e9999, which overflows to HUGE_VAL) used to work as "jump straight to the cap". Unless I'm missing a path where it misbehaves, a command that used to run will now exit 2, and nothing at runtime gets safer in return. This is the same tradeoff oranagra pointed out in PR#212, where he picked the fix that kept previously valid input working. Did you consider accepting +inf and positive overflow, and rejecting only NaN, negatives and trailing junk? The same goes for positive underflow like 1e-9999, which should behave close enough to zero.

  2. Consistency with --retry-backoff-factor. Its parser (~1791) still uses the old style: < 0.0, no errno reset, no isfinite. After this PR the two sibling factor flags accept different inputs (inf and nan pass one and fail the other). Is that deliberate, or should they share one helper so they don't drift? I wouldn't block on this, but it's an easy follow-up.

  3. Nitpicking: "values below 1 shrink it toward zero" is accurate. But with a small fractional factor, --reconnect-on-error against a dead endpoint becomes a near-busy reconnect loop after a few attempts. That isn't new in this PR, but now that the help text documents it, maybe it should also say this probably isn't what you want.

The parser change and tests look good. I'd mainly like an answer on (1) before merge, since it decides whether this PR also breaks input that used to work.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

I made the compatibility change explicit in the PR description: previously accepted infinity/overflow inputs and underflowing positive values now produce an argument error. Ordinary finite positive values, including large factors such as 1e308, retain acceptance and are covered by the new tests.

Fractional factors are preserved deliberately for compatibility. The man-page sentence describes their existing effect so users do not assume every positive factor increases delay. Adding a delay floor or requiring factors of at least one would change reconnect policy; this patch leaves that behavior unchanged while fixing explicit zero and validating numeric input. The risk of delay shrinking toward zero remains an existing limitation.

fcostaoliveira and others added 2 commits October 15, 2026 14:46
Move the "zero keeps the delay at one second" note into usage() so
make rebuild-man keeps it, and say that factors below 1 shrink the delay
toward zero. Name the range failure in the parser error, since tiny
positive values that underflow are rejected too.

Add a closed-port test asserting factor 0 logs 1.00 s for every
reconnect attempt, and note that --help exits 2 regardless, so the
diagnostic is what proves rejection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/reconnect-backoff-zero-658 branch from 7a848a5 to 013669b Compare October 15, 2026 13:47
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Follow-up on the review points, now at 013669b (rebased on master):

  1. Compat: kept rejection rather than clamping. inf only reached the 60 s cap by accident and nan silently behaved as 0. Anyone relying on the old inf behaviour can pass 1e308, which is still accepted and still tested and gives the same "straight to the cap" delay. The parser error now says "finite, representable number >= 0", which also covers tiny positive values rejected for underflow (1e-320). Whether those underflow is up to libc (glibc reports ERANGE), and the test only relies on 1e-9999, which underflows everywhere.
  2. Pinned: test_reconnect_backoff_zero_keeps_one_second_delay runs factor 0 against a closed port and asserts every logged reconnect delay is 1.00. Changing the > 0.0 guard in shard_connection.cpp to >= 0.0 makes it fail with ['0.00', '0.00', '0.00']. The man page sentence also moved into usage(), so make rebuild-man keeps it, and it now says that factors below 1 shrink the delay toward zero.
  3. Dropped the CI timeout commit. ci: run standalone test cells with PARALLELISM=2 and raise the step limit to 40 min #683 already handles CI: standalone TLS test jobs now take ~25 min and hit the 25-minute "Run tests" limit #679, raising both that step and the coverage job, so keeping the bump here would only conflict with it.

…ests

--help exits 2 whether or not the value is valid, so the rejection loop
now uses --version (0 if accepted, 2 if rejected). Add a case where an
earlier option's strtoul overflow leaves errno set to ERANGE; without the
errno reset before strtod, a valid factor would be rejected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Answers to the updated review at 19658b8:

  1. Rejecting inf and overflow. This is intentional, and no capability is lost.
    • The behaviour inf used to give, jumping straight to the cap, is still available with an ordinary finite value. --reconnect-backoff-factor=1e308 is accepted and covered by test_reconnect_backoff_large_finite_accepted, and it produces the same "attempting reconnection 1/N in 60.00 seconds" as inf did.
    • What gets rejected is only spellings that aren't real numbers: inf/infinity, nan (which > 0.0 silently treated as no backoff), and values strtod can't represent. That keeps the flag consistent with the other numeric options in config_parse_args(), which already reject ERANGE.
    • Underflow is rejected as a whole because -1e-9999 underflows to -0.0 and would otherwise slip through the sign check. One rule for every ERANGE result is simpler than special-casing its sign. A positive underflow such as 1e-9999 is not "close enough to zero" in practice: a factor that small turns a dead endpoint into a busy loop (see A fractional --reconnect-backoff-factor turns reconnects to a dead server into a busy loop (no delay floor) #688). Users who want no backoff can pass 0.
    • PR#212 kept previously valid, ordinary inputs working. This change keeps every finite, representable, non-negative value working, 0 included, which is what --reconnect-backoff-factor=0 is rejected although --help documents 0 as the default (no backoff) #658 is about.
  2. Consistency with --retry-backoff-factor. Agreed, filed as --retry-backoff-factor accepts nan, inf, overflow and an empty value #687 (2.4.0+), with a shared helper as the proposed fix. It is kept out of this PR so --reconnect-backoff-factor=0 is rejected although --help documents 0 as the default (no backoff) #658 stays a single-flag fix.
  3. Small fractional factors cause a busy loop. Filed as A fractional --reconnect-backoff-factor turns reconnects to a dead server into a busy loop (no delay floor) #688 (2.3.0+), with measurements: factor 0.5 against a dead port gave about 460k reconnect lines in 10 s, and --test-time was not honoured. That issue asks whether to add a floor or document a warning. It's a behaviour change separate from this parsing fix, so it isn't in this PR.

@fcostaoliveira
fcostaoliveira merged commit 91eec24 into master Oct 15, 2026
129 checks passed
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
--retry-backoff-factor only checked "< 0" and trailing characters, so
nan, inf, 1e9999, 1e-9999 and an empty value were accepted: nan silently
meant constant backoff, inf/overflow jumped straight to the cap, an empty
value meant 0, and the run's JSON recorded null for nan/inf.

Move the validation #668 added for --reconnect-backoff-factor into one
static parse_backoff_factor() helper (errno reset, endptr, ERANGE,
isfinite, >= 0) and use it for both flags, so they accept exactly the same
inputs: finite, representable numbers >= 0, including 0 and -0.0.
Subnormal values that strtod reports with ERANGE are rejected as before
for the reconnect flag. The retry error message now says "must be a
finite, representable number >= 0".

Adds tests/test_cli_validation_retry_backoff.py (accepted values, the
same 19 invalid values as the reconnect test, errno carry-over), wired
into the ASan/TSan/UBSan cli selections. It fails on master and passes
here.

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.

--reconnect-backoff-factor=0 is rejected although --help documents 0 as the default (no backoff)

1 participant