Skip to content

Count retried requests as processed once, and uncount dropped replays - #559

Merged
fcostaoliveira merged 3 commits into
masterfrom
fix/retry-on-error-accounting
Oct 12, 2026
Merged

fcostaoliveira merged 3 commits into
masterfrom
fix/retry-on-error-accounting

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #557. Follow-up to #556, which fixed the same leak for plain disconnects.

Problem

With --retry-on-error:

  • Double count. A request answered with a retryable error was counted as processed when the error arrived, and again when its replay completed. A --requests run therefore stopped early, with exit 0, after sending only part of the requested commands.
  • Dropped replays never uncounted. Requests that drain_replay_queue_after_reconnect() drops after a reconnect (at --max-retries, or with no captured bytes) stayed counted as generated. They held the pipeline for good:
    • with --reconnect-interval, the client stopped sending and the run failed with client(s) stopped before reaching their stop condition;
    • a --requests run never finished.

Fix

  • A request is counted as processed only at its final outcome. A response the retry path claims (m_claimed_by_retry) leaves processed unchanged, so a retried request stays in flight until its last attempt completes.
  • Every replay-path drop is therefore an uncounted request: drain_replay_queue_after_reconnect() and disconnect() uncount them with dec_reqs_generated() (from Uncount dropped in-flight requests so clients don't stall after a reconnect #556).
  • Only counted responses can reach a --reconnect-interval boundary. Otherwise a batch of only claimed responses would trigger the voluntary reconnect again at the same count (including 0).

Testing

Two new tests in tests/test_retry_on_error.py, both standalone only:

  • test_retried_requests_are_counted_once: about 1 s of retryable -OOM (CONFIG SET maxmemory 1) inside a rate-limited --requests 3000 run. Checks DBSIZE and JSON Sets/Count equal 3000.
  • test_dropped_replays_do_not_stall_client: --retry-on-error --max-retries=0 --reconnect-interval=10 with CLIENT KILL waves.

Local results, master vs this branch:

Scenario master fix
transient -OOM, --requests 3000 stops after ~1,000 SETs, exit 0 exactly 3,000
--max-retries=0, --reconnect-interval=10, kills stall, exit 1 (3/3) exit 0 (3/3)
--requests 20000, kills, --max-retries=0 hangs exactly 20,000
  • Both new tests fail on master and pass with the fix, plain and TLS.
  • Full cluster suite 354/354, unit tests 3/3, test_retry_on_error.py 7/7 (×3 plain, ×1 TLS). The full standalone suite passes; 4 throughput tests failed only when the host was overloaded and pass when rerun alone, on both master and this branch.

🤖 Generated with Claude Code


Note

Medium Risk
Touches core stop conditions (--requests, pipeline, reconnect) in the hot response/replay path; behavior change is intentional but could affect edge cases around retry and reconnect.

Overview
Fixes --retry-on-error request accounting so --requests runs and pipeline limits match real workload completion.

Processed vs answered: Adds m_reqs_answered (every response, including retryable errors) while m_reqs_processed only advances on a final outcome—responses where the retry path sets m_claimed_by_retry no longer double-count toward --requests or --reconnect-interval.

Dropped / replay path: Reconnect replay drains call dec_reqs_generated() for requests dropped at max retries or without captured bytes (including stray retry-queue entries on disconnect), so abandoned work no longer blocks the pipeline. replay_request() resumes a paused connection when the last outstanding item is a retry.

Docs & tests: CLI help clarifies that retried work counts once toward --requests. New standalone tests cover OOM retries, retry-after-last-send, and --max-retries=0 + reconnect stalls.

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

With --retry-on-error, a request answered with a retryable error was
counted as processed when the error arrived, and again when its replay
completed. A --requests run therefore stopped early, with exit 0, after
sending only part of the requested commands. Under --reconnect-interval
the extra count could also move processed past a reconnect point while
the replay was still in flight.

Requests dropped from the replay queue after a reconnect (at
--max-retries, or with no captured bytes) were never uncounted from the
generated total, so they held the pipeline for good: with
--reconnect-interval the client stopped sending and the run failed with
"client(s) stopped before reaching their stop condition", and a
--requests run never finished.

Count a request as processed only at its final outcome: a response that
the retry path claims leaves processed unchanged, so a retried request
stays in flight until its last attempt completes. Every replay-path drop
is then an uncounted request, so drain_replay_queue_after_reconnect()
and disconnect() uncount them with dec_reqs_generated(). Only counted
responses can reach a --reconnect-interval boundary.

Fixes #557

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

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

🤖 Automated first-pass review. A human maintainer still needs to review this before merge.

Thanks for this. Splitting "answered" from "processed" looks like the right model. I checked the --reconnect-interval path: because hold_pipeline() caps (processed % N) + in_flight at N, generated equals processed when a counted response reaches the boundary. Nothing can be sitting in the retry queue at that point, so the assert(m_pipeline->size() == 0) still holds. The fails-on-master / passes-with-fix tests are what this kind of change needs. A few questions:

  • Drop paths count differently. When a retryable error response runs out of retries, enqueue_retry() refuses it, so it is counted as processed and gets inc_error(). When a replay is dropped after a reconnect (at --max-retries, or with no captured bytes), dec_reqs_generated() uncounts it, so in a --requests run a new request replaces it. That replacement is what makes the "--requests 20000, kills, --max-retries=0 → exactly 20,000" row work. But the new --help line says a retried request counts toward --requests "when it succeeds or runs out of retries", and that isn't true for the connection-drop case. Also, as far as I can tell, drain_replay_queue_after_reconnect() never bumps the error counter, so these dropped requests only show up in the failed-keys file, not in the stats. Is that intended? If so, maybe the help text should say so. If not, did you consider counting them as processed with an error instead? I guess that is harder because of the reconnect-interval boundary, which may be why you uncount them.
  • Duplicated resume logic. replay_request() now repeats the m_bev_paused resume block from fill_pipeline(). It is small, but a tiny helper would keep the two from drifting. Also, fill_pipeline() checks get_connection_state() == conn_connected before resuming and replay_request() doesn't. Both callers look like they only run when the connection is up, so I think it's fine, but worth confirming.
  • Nitpicking: the PR description says two new tests, but the last commit added a third (test_retry_after_last_request_is_sent).

The core fix looks solid to me. I'd mainly like the drop-path semantics settled, either in the code or in the help text, before this merges. Since this changes counters used for stop conditions, it may be worth a second look from whoever owns the retry/reconnect path.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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 086426e. Configure here.

Comment thread shard_connection.cpp Resolved
fcostaoliveira and others added 2 commits October 12, 2026 16:16
handle_event() treated "no request processed yet" as "the run has not
started" and reset the start time on reconnect. Retried responses no
longer count as processed, so a run whose first responses were all
retryable errors restarted its --test-time clock when a connection
dropped. Track responses received separately (m_reqs_answered, which
includes responses that are retried) and use that instead.

Also note that the retry-queue drop in disconnect() is not expected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Once every request was sent, fill_pipeline paused the idle connection,
and a retry replayed afterwards was written to it but never sent: the
run failed with "client(s) stopped before reaching their stop
condition". Resume the connection when replaying.

Also restore maxmemory reliably in the tests (CONFIG GET returns bytes
keys) and note in --help how retries count toward --requests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira merged commit 50cfd7f into master Oct 12, 2026
126 checks passed
fcostaoliveira added a commit that referenced this pull request Oct 14, 2026
With --retry-on-error, a request answered with a retryable error leaves
the pipeline and waits in its connection's retry queue for the backoff.
If the run is past --test-time and that was the last pending reply,
fill_pipeline() finds every connection idle (all_connections_idle()
only checks pending replies) and calls disconnect_all(). disconnect()
moves the retry queue into the replay queue, nothing reconnects, and the
destructor frees the requests: they are never resent, never counted as
errors, never logged to --failed-keys-file, and missing from Count. The
run reports "errors 0" and exits 0. Both standalone (e.g. -BUSY) and
cluster mode (-MOVED) are affected.

Waiting for the retries instead is not bounded: --max-retries defaults
to unlimited, and in cluster mode no CLUSTER SLOTS refresh is sent after
the deadline (#590), so a MOVED retry would loop on the same node. So
account for them the way other drops are since #559/#575: when the run
ends, log every request still held for resend to --failed-keys-file as
REPLAY "run-ended-before-retry", count it as an error like a refused
retry, uncount it with dec_reqs_generated(), and print one warning.
A --requests run is unaffected: a retried request is not processed
until its final attempt, so it never ends with retries queued.

Fixes #619

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 14, 2026
With --retry-on-error, a request answered with a retryable error leaves
the pipeline and waits in its connection's retry queue for the backoff.
If the run is past --test-time and that was the last pending reply,
fill_pipeline() finds every connection idle (all_connections_idle()
only checks pending replies) and calls disconnect_all(). disconnect()
moves the retry queue into the replay queue, nothing reconnects, and the
destructor frees the requests: they are never resent, never counted as
errors, never logged to --failed-keys-file, and missing from Count. The
run reports "errors 0" and exits 0. Both standalone (e.g. -BUSY) and
cluster mode (-MOVED) are affected.

Waiting for the retries instead is not bounded: --max-retries defaults
to unlimited, and in cluster mode no CLUSTER SLOTS refresh is sent after
the deadline (#590), so a MOVED retry would loop on the same node. So
account for them the way other drops are since #559/#575: when the run
ends, log every request still held for resend to --failed-keys-file as
REPLAY "run-ended-before-resend", count it as an error like a refused
retry, uncount it with dec_reqs_generated(), and print one warning.
A --requests run is unaffected: a retried request is not processed
until its final attempt, so it never ends with retries queued.

Fixes #619

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 14, 2026
With --retry-on-error, a request answered with a retryable error leaves
the pipeline and waits in its connection's retry queue for the backoff.
If the run is past --test-time and that was the last pending reply,
fill_pipeline() finds every connection idle (all_connections_idle()
only checks pending replies) and calls disconnect_all(). disconnect()
moves the retry queue into the replay queue, nothing reconnects, and the
destructor frees the requests: they are never resent, never counted as
errors, never logged to --failed-keys-file, and missing from Count. The
run reports "errors 0" and exits 0. Both standalone (e.g. -BUSY) and
cluster mode (-MOVED) are affected.

Waiting for the retries instead is not bounded: --max-retries defaults
to unlimited, and in cluster mode no CLUSTER SLOTS refresh is sent after
the deadline (#590), so a MOVED retry would loop on the same node. So
account for them the way other drops are since #559/#575: when the run
ends, log every request still held for resend to --failed-keys-file as
REPLAY "run-ended-before-resend", count it as an error (not as an op:
it never got a final reply), uncount it with dec_reqs_generated(), and
print one warning per client.
A --requests run is unaffected: a retried request is not processed
until its final attempt, so it never ends with retries queued.

Fixes #619

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 14, 2026
With --retry-on-error, a request answered with a retryable error leaves
the pipeline and waits in its connection's retry queue for the backoff.
If the run is past --test-time and that was the last pending reply,
fill_pipeline() finds every connection idle (all_connections_idle()
only checks pending replies) and calls disconnect_all(). disconnect()
moves the retry queue into the replay queue, nothing reconnects, and the
destructor frees the requests: they are never resent, never counted as
errors, never logged to --failed-keys-file, and missing from Count. The
run reports "errors 0" and exits 0. Both standalone (e.g. -BUSY) and
cluster mode (-MOVED) are affected.

Waiting for the retries instead is not bounded: --max-retries defaults
to unlimited, and in cluster mode no CLUSTER SLOTS refresh is sent after
the deadline (#590), so a MOVED retry would loop on the same node. So
account for them the way other drops are since #559/#575: when the run
ends, log every request still held for resend to --failed-keys-file as
REPLAY "run-ended-before-resend", count it as an error (not as an op:
it never got a final reply), uncount it with dec_reqs_generated(), and
print one warning per client.
A --requests run is unaffected: a retried request is not processed
until its final attempt, so it never ends with retries queued.

Fixes #619

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.

--retry-on-error: requests double-counted as processed; replays dropped at --max-retries never uncounted

1 participant