Skip to content

Count retries still queued when a --test-time run ends (#619) - #620

Merged
fcostaoliveira merged 1 commit into
masterfrom
fix/retry-queue-dropped-at-end-of-run
Oct 14, 2026
Merged

fcostaoliveira merged 1 commit into
masterfrom
fix/retry-queue-dropped-at-end-of-run

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

With --retry-on-error and --test-time, a request that is waiting in a retry queue when the run ends is dropped silently:

  • it is never resent;
  • it isn't counted as an error;
  • it isn't written to --failed-keys-file;
  • it is missing from Count.

The run still prints errors 0 and exits 0. This happens in standalone mode (for example -BUSY) and in cluster mode (-MOVED). Details and the cluster repro are in #619.

Root cause

  1. A retryable error passes the request to enqueue_retry(). The request leaves the pipeline, so m_pending_resp drops, and it waits in m_retry_queue for the backoff timer.
  2. Suppose this was the last pending reply and the deadline has passed. Then fill_pipeline() sees finished() and all_connections_idle(), and calls disconnect_all(). all_connections_idle() only checks pending replies.
  3. disconnect() moves the retry queue into the replay queue. Nothing reconnects, so the destructor frees those requests without recording them anywhere.

A --requests run can't end with retries still queued. Since #559 a retried request is counted as processed only at its final attempt, so finished() stays false until the retry completes.

Fix

At the end of the run, client::disconnect_all() takes every request still held for resend, from the retry queue and the replay queue, using pop_replay_request(). Each one is handled like the drops in #559/#575, plus an error count:

  • It's logged to --failed-keys-file as REPLAY with status run-ended-before-resend. The status says "resend" because the replay-queue case is a reconnect resend, not a retry.
  • It's counted as an error (inc_error()), so it shows in the errors N progress tail and in Prometheus. Unlike a refused retry, it is not counted as an op: it never got a final reply, so there is no latency to record.
  • It's uncounted with dec_reqs_generated(). Nothing reads that count after disconnect_all(), so this call can't be observed, and a mutant that removes it survives the tests. It stays for consistency with the other drop paths (Count retried requests as processed once, and uncount dropped replays #559/Resend held retries when a slot map refresh retires a connection #575), so the generated and processed counts agree whatever reads them later.

A warning line reports how many requests were dropped. It's printed once per client that dropped any, not once per run, so -c 2 or -t N can print several lines.

Why not drain instead? Waiting for the retries is not bounded. --max-retries defaults to unlimited. In cluster mode, CLUSTER SLOTS isn't sent after the deadline, so a MOVED retry would go back to the same node: that is #590, which #591 fixes only while replies are still pending. Draining would turn this silent drop into a hang. Accounting keeps --test-time meaning "stop at the deadline" and makes the loss visible.

disconnect_all() is only called from the two finished() && all_connections_idle() end-of-run checks in shard_connection.cpp, so nothing changes mid-run.

Interactions with other PRs. This PR is rebased on master f1cb946, where #591, #600 and #613 have merged. None of them touch client::disconnect_all().

Tests

New test test_retries_left_at_end_of_test_time_are_counted in tests/test_retry_on_error.py. It uses a scripted standalone peer, with no Redis needed:

  1. The peer answers +OK, then holds every reply from 0.3 s.
  2. At 1.5 s, after --test-time=1, it writes all 8 held replies at once: +OK and 7 × -BUSY. --retry-backoff-ms=200 keeps the retries in the queue.
  3. It checks that abandoned (failed replies minus the retries the peer received) is greater than 0. That abandoned count must equal both the run-ended-before-resend lines in --failed-keys-file and the final errors N.

Local results (RLTest):

Binary new test
origin/master 6b6d6df 0/10: 0 == 7 (no failed-keys lines, errors 0)
this PR (before rebase) 10/10, plus 4/4 run 4-way in parallel
this PR, rebased on f1cb946 5/5; whole test_retry_on_error.py 16/16 (standalone, RLTest --env oss)

The master failure wasn't rerun after the rebase. The test still checks for the run-ended-before-resend lines and the errors N count, which master doesn't produce.

Scripted cluster peer from the #591 review (MOVED burst after the deadline):

Setup master: errors / failed-keys lines this PR
--pipeline=1 0 / 0 1 / 1
--pipeline=4 0 / 0 4 / 4
--pipeline=16 0 / 0 16 / 16
-c 2 --pipeline=4 0 / 0 8 / 8

Related suites with this PR:

  • standalone: test_retry_on_error.py 9/9, test_reconnections.py 7 pass / 3 skip;
  • OSS cluster (3 shards): test_retry_on_error.py 4 pass / 5 skip, test_cluster_redirect_stats.py 5/5, test_cluster_transaction.py 15 pass / 2 skip, test_reconnections.py 7 pass / 3 skip.

CI runs the full matrix.

Fixes #619

Affected versions

2.4.0 through 2.5.2 (latest) and master.

🤖 Generated with Claude Code


Note

Medium Risk
Changes end-of-run teardown and error accounting for --retry-on-error + --test-time; behavior is bounded to disconnect_all() but affects reported errors and failed-keys output.

Overview
Fixes a silent loss of work when --test-time ends while --retry-on-error still has requests waiting in retry/replay queues (not counted as pending replies).

client::disconnect_all() now drains each connection’s replay queue after disconnect(), treating every stranded retry like a refused replay: log to --failed-keys-file as REPLAY / run-ended-before-resend, inc_error(), dec_reqs_generated(), plus a one-line warning with the count.

Adds test_retries_left_at_end_of_test_time_are_counted using a scripted TCP peer that bursts retryable -BUSY replies after the deadline, asserting failed-keys lines match the final errors N tail.

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

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

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

Thanks for this, and for the detailed write-up. The root cause matches what I see in the code: all_connections_idle() only looks at pending replies, and disconnect() moves the retry queue into the replay queue, which then gets freed. Accounting for these at teardown, rather than draining, also seems right to me given that --max-retries is unlimited by default and #590 applies. The test is the kind I'd hope to see: it reproduces the exact burst-after-deadline case, and the PR shows it failing on master (0/10). A few comments:

  1. I'm checking the error accounting against the other drop paths. As far as I can tell, drain_replay_queue_after_reconnect() (connection-dropped, no-captured-bytes-for-replay) and cluster_client::hand_off_replay_requests() (no-slot-owner-for-replay, slot-owner-down-for-replay) log to --failed-keys-file and call dec_reqs_generated(), but they don't call inc_error(). With this PR, run-ended-before-resend would be the only REPLAY drop that shows up in errors N. I think counting it is the right call, since otherwise it's invisible. But should the other drops count too, so that the failed-keys line count and errors N agree for every REPLAY reason? If that's left for a follow-up, maybe say so explicitly.

  2. This log + delete + count loop now appears in about three places: here, drain_replay_queue_after_reconnect() and hand_off_replay_requests(). If it's easy, a small shared helper on shard_connection (taking a reason and an error/no-error flag) might keep them from drifting apart, much as point 1 suggests they already have. This isn't a blocker, so feel free to push back.

  3. Did you consider whether a run that drops requests this way should still exit 0? I believe that matches the other drop paths, so I'm not asking for a change. It might be worth a sentence in the PR, since anyone running this in CI will only see the warning line.

  4. Nitpicking: the warning says "held for retry", but the drained queue includes reconnect replays too. You already picked "resend" for the status string for that reason, so "held for resend" would keep the two consistent.

  5. Nitpicking: gettimeofday() runs once per request inside the loop. It only runs at teardown, so the cost doesn't matter, but hoisting it out of the loop would make the timestamps on one teardown identical. Not worth changing on its own.

The core fix looks solid to me. I'd mainly like an answer on the error-accounting asymmetry in point 1 before this merges.

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

@fcostaoliveira
fcostaoliveira force-pushed the fix/retry-queue-dropped-at-end-of-run branch 2 times, most recently from 9e7967c to c3e94cd Compare October 14, 2026 08:07
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
fcostaoliveira force-pushed the fix/retry-queue-dropped-at-end-of-run branch from c3e94cd to 9184208 Compare October 14, 2026 08:07
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Answers point by point (head 9184208, rebased on f1cb946):

  1. inc_error() asymmetry: yes, it's intended. The two cases aren't the same:

    It counts as an error but, unlike a refused retry, not as an op: it never got a final reply. I've reworded the code comment to say so. Whether the mid-run replay drops should also count as errors is a fair question, but it changes existing output for runs that don't touch this path. I'd rather take it in a separate issue than widen this PR.

  2. Status name: agreed, done. It's now run-ended-before-resend, since the replay-queue case (waiting on a reconnect) isn't strictly a retry. I updated the test and the PR body to match.

  3. Unused --json-out-file: removed. The test checks the failed-keys file and the final errors N progress line. Errors aren't in the JSON.

  4. gettimeofday() per request: left as is, to match drain_replay_queue_after_reconnect() and hand_off_replay_requests(). It only runs at teardown.

After the rebase the new test passes 5/5, and the whole test_retry_on_error.py passes 16/16 (standalone, RLTest --env oss).

🤖 Generated with Claude Code

@fcostaoliveira
fcostaoliveira merged commit ade1d56 into master Oct 14, 2026
127 checks passed
fcostaoliveira added a commit that referenced this pull request Oct 15, 2026
With --retry-on-error, a request memtier gives up on after its connection
drops is logged to --failed-keys-file but was never counted as an error,
so the run reported "errors 0". Since #620 a request abandoned when the
run ends is counted, so whether a lost request reached the error total
depended only on where it was dropped.

Add connections_manager::abandon_requests(), which uncounts the requests
from the generated total (as the drop sites already did) and counts each
one as an error, and use it at every place a request held for resend is
dropped for good:

- drain_replay_queue_after_reconnect(): "connection-dropped" (max
  retries reached) and "no-captured-bytes-for-replay"
- cluster_client::hand_off_replay_requests(): "transaction-not-replayed",
  "no-slot-owner-for-replay", "slot-owner-down-for-replay"
- shard_connection::disconnect() under --retry-on-error:
  "transaction-not-replayed" and requests with no captured bytes
- client::disconnect_all(): "run-ended-before-resend" (unchanged count)

A request moved to the replay queue and later resent is not counted; it is
counted only where it is finally dropped. Requests dropped on a disconnect
without --retry-on-error are still only uncounted, as before. The
failed-keys rows are unchanged.

Fixes #652

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
With --retry-on-error, a request memtier gives up on after its connection
drops is logged to --failed-keys-file but was never counted as an error,
so the run reported "errors 0". Since #620 a request abandoned when the
run ends is counted, so whether a lost request reached the error total
depended only on where it was dropped.

Add connections_manager::abandon_requests(), which uncounts the requests
from the generated total (as the drop sites already did) and counts each
one as an error, and use it at every place a request held for resend is
dropped for good:

- drain_replay_queue_after_reconnect(): "connection-dropped" (max
  retries reached) and "no-captured-bytes-for-replay"
- cluster_client::hand_off_replay_requests(): "transaction-not-replayed",
  "no-slot-owner-for-replay", "slot-owner-down-for-replay"
- shard_connection::disconnect() under --retry-on-error:
  "transaction-not-replayed" and requests with no captured bytes
- client::disconnect_all(): "run-ended-before-resend" (unchanged count)

A request moved to the replay queue and later resent is not counted; it is
counted only where it is finally dropped. Requests dropped on a disconnect
without --retry-on-error are still only uncounted, as before. The
failed-keys rows are unchanged.

Fixes #652

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
With --retry-on-error, a request memtier gives up on after its connection
drops is logged to --failed-keys-file but was never counted as an error,
so the run reported "errors 0". Since #620 a request abandoned when the
run ends is counted, so whether a lost request reached the error total
depended only on where it was dropped.

Add connections_manager::abandon_requests(), which uncounts the requests
from the generated total (as the drop sites already did) and counts each
one as an error, and use it at every place a request held for resend is
dropped for good:

- drain_replay_queue_after_reconnect(): "connection-dropped" (max
  retries reached) and "no-captured-bytes-for-replay"
- cluster_client::hand_off_replay_requests(): "transaction-not-replayed",
  "no-slot-owner-for-replay", "slot-owner-down-for-replay"
- shard_connection::disconnect() under --retry-on-error:
  "transaction-not-replayed" and requests with no captured bytes
- client::disconnect_all(): "run-ended-before-resend" (unchanged count)

A request moved to the replay queue and later resent is not counted; it is
counted only where it is finally dropped. Requests dropped on a disconnect
without --retry-on-error are still only uncounted, as before. The
failed-keys rows are unchanged.

Fixes #652

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
With --retry-on-error, a request memtier sent and then gave up on (never
resent, never answered) was logged to --failed-keys-file but not counted
in the error total, so runs reported "errors 0" next to hundreds of
dropped rows. Since #620 the run-end drop was counted; every other drop
site only uncounted the request.

Add connections_manager::abandon_requests(), which uncounts the requests
and counts each one as an error, and shard_connection::abandon_replay_requests(),
which logs and abandons everything held for resend on a connection. Use
them wherever a request is dropped for good:

- drain_replay_queue_after_reconnect(): connection-dropped,
  no-captured-bytes-for-replay
- cluster_client::hand_off_replay_requests(): transaction-not-replayed,
  no-slot-owner-for-replay, slot-owner-down-for-replay
- shard_connection::disconnect(): transaction-not-replayed, and the new
  not-replayable for requests without captured bytes
- client::disconnect_all(): run-ended-before-resend (count unchanged)
- client_group::run(), once the thread's event loop returns: everything
  still held, or still in flight under --retry-on-error, on every
  connection of the thread. The connection that ended the thread logs
  with max-reconnect-attempts-exceeded, or connection-lost-no-reconnect
  without --reconnect-on-error; the others with thread-ended-before-resend.
  One stderr warning per thread. On Ctrl+C only the queued requests are
  logged and counted; requests in flight are dropped as before.

A request moved to the replay queue and later resent is not counted.
Without --retry-on-error, requests dropped on a disconnect are still only
uncounted. The memtier_errors_total HELP text and docs now include
requests given up on without a reply.

Fixes #652

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: retries still queued when a --test-time run ends are dropped silently (not resent, not counted, not logged)

1 participant