Repository navigation
fix(reconnect,retry): cap exponential backoff at 60s - #433
Conversation
shard_connection.cpp had two exponential-backoff multiplications with no upper bound. With factor=2.0 and --max-reconnect-attempts=0 the timer doubles indefinitely; after ~30 attempts the next scheduled reconnect is ~34 years out. event_add() silently absorbs the value and the benchmark goes effectively dark instead of surfacing the underlying failure. Adds MEMTIER_BACKOFF_CAP_SEC = 60s and clamps after every factor multiplication (both reconnect_backoff_delay and retry_backoff_ms). Refs: 2.4 review finding #13 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
Bugbot flagged two real issues in PR #433: 1. handle_reconnect_timer_event() had a second m_current_backoff_delay *= reconnect_backoff_factor without the MEMTIER_BACKOFF_CAP_SEC clamp. When a scheduled reconnect itself failed, the delay still grew unboundedly. Now capped at both sites. 2. test_reconnect_backoff_cap_60s regex used a [^i]+ negated class that could never match the "unlimited" log variant, so under --max-reconnect-attempts=0 the test ran the cap assertion against an empty match list (vacuous pass). Regex rewritten to match the actual log format. Refs: bugbot HIGH x2 on PR #433 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Both bugbot HIGH findings addressed in eb4ea29: cap applied at second multiplication site in handle_reconnect_timer_event; test regex rewritten to match unlimited-mode log lines so the cap assertion is actually exercised. |
…keep memtier alive
Bugbot caught that the cap-regression test used --requests=forever, which
is not a valid memtier option. strtoull("forever") returns 0, triggering
immediate exit with "requests must be greater than zero" -- the test ran
memtier for ~0ms, observed zero reconnect attempts, found no delays in
the log, hit the warning branch, and passed vacuously.
Switched to --test-time=20 (bounded) which keeps memtier alive long
enough for the exponential backoff to fire the cap multiple times. Test
now actually exercises the production code path.
Also strengthens assertions: the "skip with warning" branch is replaced
by a hard assertGreaterEqual(len(delays), 2) that fails if memtier exits
immediately, plus a documented note that the libevent non-blocking connect
resets the backoff counter on each cycle so end-to-end cap-value
observation is not feasible in this test design.
Refs: bugbot HIGH on PR #433 (follow-up).
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Bugbot HIGH (vacuous test) addressed in e717a98: swapped --requests=forever for --test-time=20 so memtier actually stays alive through multiple reconnect attempts. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e717a98. Configure here.
RLTest assertions are soft - assertGreaterEqual records failure but doesn't halt execution. Without an explicit guard, a vacuous-pass pattern recurs: assertion records failure, max([]) raises ValueError, the real failure reason is masked by the traceback. Adds `if not delays: return` after the soft assertion so subsequent max() / sequence checks only run when delays were observed. Refs: bugbot LOW on PR #433 follow-up. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Bugbot LOW (max on empty list) addressed in 43fcaaa: explicit guard after the soft assertion so the test fails cleanly with the assertion message instead of a confusing ValueError traceback. |

Problem
shard_connection.cpphad two exponential-backoff multiplications with no upper bound:m_current_backoff_delay *= reconnect_backoff_factor) — triggered on every connection error when--reconnect-on-erroris set.m_current_retry_backoff_ms *= retry_backoff_factor) — triggered on each retry drain schedule.With a factor of 2.0 and
--max-reconnect-attempts=0(unlimited), the delay doubles on every attempt. After ~30 doublings, the next scheduled reconnect or retry is approximately 34 years in the future.event_add()silently absorbs the absurdtimevalwithout error, and the benchmark goes effectively dark — no reconnects, no retries, no visible failure — instead of surfacing the underlying connectivity problem.Fix
Adds two file-scope constants near the top of
shard_connection.cpp:After each
*= factormultiplication:MEMTIER_BACKOFF_CAP_SEC(60 s)MEMTIER_BACKOFF_CAP_MS(60 000 ms)No parser changes, no flag defaults changed, no semantic changes outside the runtime multiplication sites.
Test
Adds
test_reconnect_backoff_cap_60stotests/test_reconnections.py. It targets a guaranteed-closed port with--reconnect-backoff-factor=4.0 --max-reconnect-attempts=0for 10 s, then:"attempting reconnection … in X.XX seconds"line from stderr and assertsmax(delays) <= 60.0 s.Refs: 2.4 review finding #13
Note
Low Risk
Runtime-only clamps on reconnect/retry timer delays with no CLI or auth changes; regression test covers the reconnect logging path.
Overview
Caps unbounded exponential backoff on reconnect and retry-on-error paths in
shard_connection.cppso scheduled libevent delays cannot grow without limit (which could leave the benchmark idle for years while errors keep accumulating).Introduces
MEMTIER_BACKOFF_CAP_SEC(60 s) andMEMTIER_BACKOFF_CAP_MS(60 000 ms) and clampsm_current_backoff_delayandm_current_retry_backoff_msimmediately after each*= backoff_factormultiplication inattempt_reconnect, failed reconnect retries, andenqueue_retry.Adds RLTest
test_reconnect_backoff_cap_60sagainst a closed port with aggressive reconnect backoff: asserts no SIGABRT, at least two reconnect log lines, and parsed “in X.XX seconds” delays never exceed 60 s (regex fixed so the “(unlimited)” log variant is matched).Reviewed by Cursor Bugbot for commit 43fcaaa. Bugbot is set up for automated code reviews on this repo. Configure here.