Skip to content

Floor the retry delay at 100 ms for fractional --retry-backoff-factor - #727

Merged
fcostaoliveira merged 1 commit into
masterfrom
fix/712-retry-backoff-floor
Oct 16, 2026
Merged

fcostaoliveira merged 1 commit into
masterfrom
fix/712-retry-backoff-floor

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

With --retry-on-error, a --retry-backoff-factor below 1 and the default unlimited --max-retries (-1), a request the server keeps rejecting is resent with a delay that shrinks toward 0 ms. After about 10 resends, a 100 ms base delay drops below 0.1 ms, and from then on the request is resent in a tight loop. The "back off" setting gives the highest request rate possible.

Reproduced on master 427d721 with the issue's command (server with maxmemory 1, noeviction, --retry-backoff-ms 100 --retry-backoff-factor 0.5): retries 5151904 (+429097) per second, and 5,151,968 SET rejected_calls on the server.

Root cause

retry_backoff_delay_ms(base_ms, factor, resends) = base_ms * factor^resends (retry_backoff.h, from #700) has an upper cap (60 s) but no lower bound. #694 fixed the same problem for reconnects with MEMTIER_RECONNECT_MIN_DELAY_SEC = 0.1. The retry path never got a floor.

Fix

retry_backoff_delay_ms() now settles at MEMTIER_RETRY_BACKOFF_MIN_MS (100 ms, the same floor as reconnects), or at --retry-backoff-ms when that is smaller. Because of that:

  • --retry-backoff-ms 0 still means no delay, and a base below 100 ms is never raised (with a base of 100 ms or less, a factor < 1 now keeps the delay constant).
  • Factor 0, factors >= 1 and the 60 s cap behave as before.
  • A factor in (0, 1) still shrinks the delay, but it stops at 100 ms, so each queued request is resent about 10 times per second.

--help and the man page now describe the floor. The README does not describe the delay, so it is unchanged.

The diff touches only retry_backoff.h, its unit test, the docs and a new RLTest. It stays out of client.cpp and shard_connection.cpp (#724).

Tests

  • tests/unit/retry_backoff_test.cpp: covers decay to 100 ms, a base below 100 ms acting as its own floor, underflow (1e-300, DBL_MIN) ending at the floor rather than 0, and base 0. Built against master's header it gives 9 failures; with the fix it passes.
  • tests/test_retry_backoff_floor.py (new): saves maxmemory / maxmemory-policy on every master, then sets maxmemory 1 / noeviction so every SET fails with -OOM. It runs memtier with --retry-backoff-ms=400 --retry-backoff-factor=0.5 --max-retry-queue=16, so the delay decays 400 → 200 → 100 and then stays at the floor. It measures the server's SET rejected_calls over 3 s per stuck request (memtier's retried_ops, which must not change during the window), kills memtier, and restores both settings in finally. Killing memtier keeps the test independent of --retry-on-error: a --test-time run where every request keeps failing never ends (finished() only advances on completed ops; #669's drain grace misses requests held in the retry queue) #715. The test accepts 5–20 resends/s per request. The expected rate is 10/s. If the floor were the 400 ms base instead of 100 ms, the rate would be 2.5/s and the test would fail.
build env runs stuck requests resends/s per request result
master ec4e6fa oss 3 16 9.2k–11.6k 3/3 FAIL
master ec4e6fa oss-cluster (3 shards) 1 3 21k FAIL
mutant: floor = base_ms oss 2 16 2.7 2/2 FAIL
this PR oss 5 16 10.0 5/5 PASS
this PR oss-cluster (3 shards) 3 3 10.0 3/3 PASS

In cluster mode about one request per shard connection gets stuck, versus up to --max-retry-queue on a standalone connection. That is why the test measures the rate per stuck request rather than per connection.

On the earlier head, the full test_retry_on_error.py suite passed (27/27) and make check passed (9/9). This update changes only the new test.

Fixes #712

Affected versions

2.4.0 through 2.5.2 (latest) and master. The bug was introduced by 08cfc24 (#381, --retry-on-error), which added m_current_retry_backoff_ms *= retry_backoff_factor with only an upper cap. #700 moved the formula into retry_backoff_delay_ms() without adding a lower bound. Confirmed by running on master 427d721 and ec4e6fa; 2.4.0–2.5.2 are derived from history (same code).

🤖 Generated with Claude Code


Note

Low Risk
Narrow change to retry delay calculation for fractional backoff factors; successful paths unchanged and covered by unit and integration tests.

Overview
Fixes a runaway retry loop when --retry-on-error uses a --retry-backoff-factor below 1 with unlimited --max-retries: the computed delay could shrink to 0 ms and hammer the server with resends.

retry_backoff_delay_ms() in retry_backoff.h now applies a 100 ms floor (aligned with reconnect backoff), or keeps --retry-backoff-ms when that value is smaller—so --retry-backoff-ms 0 still means immediate retries and small bases are not raised.

Help text and the man page document the floor. Unit tests in retry_backoff_test.cpp are updated, and a new RLTest test_retry_backoff_floor.py asserts per-request resend rate stays near ~10/s under sustained -OOM failures (regression for #712).

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

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

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

Thanks for this. The fix is small and matches the reconnect floor from #694. --retry-backoff-ms 0 stays immediate and a base under 100 ms is never raised, so I don't see a compat problem for anyone who wasn't depending on the tight loop. The unit cases (decay to 100 ms, 1e-300/DBL_MIN underflow, base 0) cover the edges I'd have asked about. A few comments:

  • Just checking: the PR description seems to describe an earlier version of the RLTest. It says the test asserts "fewer than 640 resends/s per connection", and the results table reports per-connection rates (155–160/s, 10/s). The committed test uses a 400 ms base and measures resends per stuck request (via retried_ops), with a 5–20/s window. The commit message matches the code, so it's only the body that's out of date. Could you sync it so whoever reads it later sees the bound that's actually enforced?

  • On the lower bound (rate >= 5): I think it's a good addition, since it's what tells a 100 ms floor apart from a floor at the 400 ms base. I wonder how much margin it has on a loaded CI runner, though. The standalone cells run with PARALLELISM=2 since ci: run standalone test cells with PARALLELISM=2 and raise the step limit to 40 min #683, so a slow event loop or a late rejected_calls sample could push it under 5. If you've already run it under that setting a few times, ignore this.

  • Nitpicking: the test reads retried_ops from the live stderr progress line by regex. That works today, since both retry branches print it, but it ties the test to the wording of that line. If it's easy to get the stuck count some other way (e.g. from --max-retry-queue on standalone), that might be sturdier. Not a blocker.

The core change looks right to me. I'd just want the description updated before this merges.

(would file this as a comment, not a formal block)

…#712)

A --retry-backoff-factor below 1 shrank each request's retry delay on
every resend with no lower bound. With the default unlimited
--max-retries, a request the server keeps rejecting (e.g. -OOM) reached a
0 ms delay after ~10 resends and was resent in a tight loop: about
100k-400k resends per second per connection, the opposite of a backoff.

retry_backoff_delay_ms() now settles at MEMTIER_RETRY_BACKOFF_MIN_MS
(100 ms, the same floor #694 gave reconnects), or at --retry-backoff-ms
when that is smaller, so --retry-backoff-ms 0 still means no delay and a
small base is never pushed up. Factor 0, factors >= 1 and the 60 s cap
are unchanged. --help and the man page say so.

Tests: the unit test covers the floor (decay to 100 ms, a base below
100 ms as its own floor, underflow, base 0). A new RLTest makes every SET
fail with -OOM (maxmemory 1, noeviction), runs a 400 ms base with factor
0.5 and measures server rejected_calls per stuck request: ~9k-21k/s on
master, 10/s with the fix (5-20/s accepted, so a floor at the base, 2.5/s,
fails too). It restores maxmemory and maxmemory-policy afterwards.

Fixes #712

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/712-retry-backoff-floor branch from 70ad0ac to ba3e893 Compare October 16, 2026 18:09
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. On both points:

Why a fixed 100 ms floor, not one derived from base_ms, and why not reject factor < 1 with --max-retries=-1:

  • Same as reconnects. Floor the reconnect delay at 0.1 s for fractional --reconnect-backoff-factor #694 floors the reconnect delay at a fixed 0.1 s (MEMTIER_RECONNECT_MIN_DELAY_SEC). Using the same absolute floor here means both backoffs behave the same way and the help text can describe them the same way.
  • What the floor bounds is the resend rate, which is absolute. Its job is to cap how often one request hits the server (about 10 times per second). A floor derived from the base, such as base/16, would still allow tens of thousands of resends per second for a small base. base_ms is still the floor when it is below 100 ms, so --retry-backoff-ms 0 and small bases keep working as before.
  • Rejecting would break existing configs. --retry-backoff-factor < 1 with the default unlimited --max-retries has been accepted since 2.4.0. Turning it into a startup error would break existing command lines that work with bounded retries or with servers that recover. A floor keeps them running and only removes the tight loop.

State leak: fixed in ba3e893. The test now saves maxmemory and maxmemory-policy on every master and restores both in finally. The CONFIG SETs are inside the try, so the test also restores the masters it already changed if it fails partway through. The test now uses a 400 ms base, so the decay-to-floor path runs, and it checks the rate per stuck request (5–20/s, expected 10). The updated numbers are in the PR description.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Following up on the points from the 18:10 version of the review:

  • Description: updated for the per-stuck-request measurement (400 ms base, 5–20 resends/s per stuck request).
  • Margin of the rate >= 5 lower bound under PARALLELISM=2 / loaded runners: reviewers measured the rate with the whole RLTest run pinned to one CPU, under 2x CPU oversubscription and under ASan, standalone and cluster. Every run measured 9.3–10.0 resends/s per stuck request, so there is about 2x headroom on each side. The "Test Single Endpoint: TCP Plaintext" CI cell (PARALLELISM=2) also passed.
  • Regex on the live progress line (retried_ops N): that's deliberate. The stuck-request count isn't exposed anywhere else while the run is going, and the JSON is written only at the end, after the kill. If the progress-line wording changes, the test fails on its stuck_before/stuck_after assertion rather than passing silently. I'll leave it as is.

@fcostaoliveira
fcostaoliveira merged commit e09ee54 into master Oct 16, 2026
129 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant