Repository navigation
Floor the retry delay at 100 ms for fractional --retry-backoff-factor - #727
Conversation
|
🤖 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.
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]>
70ad0ac to
ba3e893
Compare
|
Thanks. On both points: Why a fixed 100 ms floor, not one derived from
State leak: fixed in ba3e893. The test now saves |
|
Following up on the points from the 18:10 version of the review:
|
Problem
With
--retry-on-error, a--retry-backoff-factorbelow 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 SETrejected_callson 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 withMEMTIER_RECONNECT_MIN_DELAY_SEC = 0.1. The retry path never got a floor.Fix
retry_backoff_delay_ms()now settles atMEMTIER_RETRY_BACKOFF_MIN_MS(100 ms, the same floor as reconnects), or at--retry-backoff-mswhen that is smaller. Because of that:--retry-backoff-ms 0still 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).--helpand 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 ofclient.cppandshard_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): savesmaxmemory/maxmemory-policyon every master, then setsmaxmemory 1/noevictionso 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 SETrejected_callsover 3 s per stuck request (memtier'sretried_ops, which must not change during the window), kills memtier, and restores both settings infinally. 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.In cluster mode about one request per shard connection gets stuck, versus up to
--max-retry-queueon 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.pysuite passed (27/27) andmake checkpassed (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 addedm_current_retry_backoff_ms *= retry_backoff_factorwith only an upper cap. #700 moved the formula intoretry_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-erroruses a--retry-backoff-factorbelow 1 with unlimited--max-retries: the computed delay could shrink to 0 ms and hammer the server with resends.retry_backoff_delay_ms()inretry_backoff.hnow applies a 100 ms floor (aligned with reconnect backoff), or keeps--retry-backoff-mswhen that value is smaller—so--retry-backoff-ms 0still means immediate retries and small bases are not raised.Help text and the man page document the floor. Unit tests in
retry_backoff_test.cppare updated, and a new RLTesttest_retry_backoff_floor.pyasserts 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.