Skip to content

End a --retry-on-error --test-time run whose retries never succeed after the drain grace - #724

Merged
fcostaoliveira merged 1 commit into
masterfrom
fix-715-retry-deadline
Oct 16, 2026
Merged

fcostaoliveira merged 1 commit into
masterfrom
fix-715-retry-deadline

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Decision: a --test-time run whose --retry-on-error retries never succeed is now ended by #669's drain grace (TEST_TIME_DRAIN_GRACE_SECS, 10 s after the deadline), the same way as a run waiting for replies that never come. Until then, retries go on after --test-time as before. That is the existing contract pinned by test_moved_after_test_time_refreshes_slots: a MOVED that arrives after the deadline still refreshes the slot map. The report covers --test-time and not the grace.

Behaviour change to note: a run where every request always fails now exits 0 at test_time + 10 s, with the requests counted as errors. On master it ran forever, or, with the default --connection-stage-timeout (30 s), exited 2 at that timeout. The second case only applies when test_time + 10 < --connection-stage-timeout.

(The first version of this PR ended the run on wall time at the deadline. That broke test_moved_after_test_time_refreshes_slots and could still overshoot by one retry backoff. It has been replaced.)

Problem

With --retry-on-error and the default unlimited --max-retries, a --test-time run against a server that rejects every request (e.g. maxmemory 1 + noeviction, so every SET gets -OOM) never ends. It resends its retries until killed, or until --connection-stage-timeout aborts it with rc=2. See #715.

Root cause

  • client::finished() compares m_stats.get_duration() with --test-time. That is m_cur_stats.m_second, which only moves in roll_cur_stats() from the update_*_op() calls, i.e. when an op completes. A reply handed to enqueue_retry() records nothing, so the clock stays at 0.
  • End a --test-time run whose server stops replying (10 s drain grace) #669's drain grace exists to end runs like this, but client::abandon_unanswered_requests() returned early when all_connections_idle(), i.e. get_pending_resp() == 0. A request held in the retry queue for its backoff is not pending, and with --pipeline 1 that is almost always what the tick sees.
  • 50cfd7f (Count retried requests as processed once, and uncount dropped replays #559) made the retries actually go out after a connection was paused, which turned an early stop into an endless run.

Fix

  • abandon_unanswered_requests() also ends a client that still holds retries (shard_connection::holds_retries()) once the grace is over:
    • its held requests are counted as errors, with failed-keys status run-ended-before-resend;
    • its end time is start + --test-time, so Runtime and the rates cover --test-time.
  • handle_end_stalled_clients() reports the two kinds of client separately, based on what each client actually had, once per thread:
    • N client(s) got no reply to M request(s) 10 seconds after the test time ended; abandoned them (...) for clients waiting for replies. This includes clients waiting only for setup replies, as before.
    • N client(s) were still retrying M request(s) 10 seconds after the test time ended; ended them (counted as errors, not resent). for clients holding retries. This line replaces one "held for retry" line per client: -t 2 -c 8 now prints 2 lines instead of 16 when all clients cross the grace on the same 1 s tick. Clients that cross it on different ticks print one pair of lines per tick (at most two lines per thread per tick). The counts still add up exactly.
    • A client that had both (the tick found a resend on the wire) is in both lines. In my -t 2 -c 8 run, 1 of 16 clients was.
  • A client that is only waiting for a reconnect is still left alone, with or without --retry-on-error: its in-flight requests wait in the replay queue, not the retry queue.
  • finished() and the retry drain timer are unchanged:
    • the grace check is posted from the main thread's 1 s tick (end_stalled_clients() → event_base_once), so a long backoff cannot hold the run past test_time + grace + about 1 s;
    • a drain timer clamped to that instant would spin until the tick arrives.
  • README ("End of a --test-time run"), the man page and --help describe this. JSON "Unanswered requests" does not include held retries.

Overlap with #666: this PR touches neither run_is_over() nor run_deadline(); it only extends the #669 abandon path. Dependency: when the server dies after the deadline under --reconnect-on-error, the run still hangs with this PR alone (that is #656, fixed by #666). With #666 merged too, it ends at 7.0 s with duration 3000 and 64 run-ended-before-resend rows.

Test evidence

test_retry_on_error.py::test_test_time_ends_when_every_request_is_retried (new):

  • Setup: every SET gets -OOM, --test-time 3, --pipeline 1, --failed-keys-file. Cases: backoff 100 ms with factor 0, backoff 100 ms with factor 2, a 20000 ms backoff, and a control without --retry-on-error. Times are measured with time.monotonic(), and the grace is read from the warning text.

  • Retry cases assert:

    • test_time + grace <= elapsed < test_time + grace + 3;
    • JSON Total duration in [3000, 3200) ms;
    • one or both warnings, with the same grace;
    • the "still retrying" count equals the run-ended-before-resend rows, and the "no reply" count equals the no-reply-after-test-time rows, which equals JSON Unanswered requests;
    • no other rows, and the final errors total equals the sum.

    Accepting both categories makes the test robust when the tick finds a resend on the wire.

  • The control asserts the run ends in [test_time, test_time + 3) with neither warning.

test_test_time_stalled_server.py:

  • test_test_time_reconnecting_client_left_alone now asserts that neither warning appears. A mutant that removes the idle gate (M1) fails it.
  • New ..._left_alone_retry_on_error: the same test with --retry-on-error. A mutant where holds_retries() lacks the emptiness check (M4) fails it.

Results:

  • origin/master 5b92b23: the new test FAILS, with all 3 retry cases still running at the 23 s kill.
  • This branch: the new test PASSES 5/5 (4 runs on 5b92b23 + 1 after rebasing on e09ee54).
  • M1: both reconnect tests fail. M4: the --retry-on-error reconnect test fails.
  • Also run locally on this branch, all passing:
    • full test_retry_on_error.py: 28/28;
    • test_test_time_stalled_server.py: 5/5 standalone and 5/5 oss-cluster;
    • test_cluster_redirect_stats.py on oss-cluster: 9/9;
    • make check: 10/10.

Manual repro (-t 1 --ratio 1:0 --retry-on-error --connection-stage-timeout 0, maxmemory 1 + noeviction):

args master this branch (wall / JSON Total duration)
-c 1 --pipeline 1 --retry-backoff-ms 100 --retry-backoff-factor 0 --test-time 3 killed at 20 s 14.0 s / 3000 ms
-c 1 --pipeline 1 --retry-backoff-ms 20000 --test-time 3 killed 14.0 s / 3000 ms
-c 1 --retry-backoff-ms 1000 --retry-backoff-factor 2 --test-time 3 killed 14.0 s / 3000 ms
-t 2 -c 8 --retry-backoff-ms 100 --test-time 3 killed 14.0 s / 3000 ms; per thread: 8 clients still retrying 512 / 476 requests, plus 1 client with 36 unanswered
-c 1 --pipeline 1 --test-time 3 (no retry) 3.1 s 3.1 s / 3000 ms

Whole-second wall times come from the main thread's sleep(1) poll for thread completion, not from a delay in the run. The JSON duration of the same runs is test_time. In the first version of this PR, a factor-0 run had a JSON duration of 3036 ms and showed 4.0 s wall, and a 0 ms backoff showed 3.0 s wall.

Fixes #715

Affected versions

master only (not in a release). The underlying condition goes back to 2.4.0.

🤖 Generated with Claude Code

@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 root-cause write-up makes the change easy to follow. Extending #669's abandon path, instead of touching finished() or adding a timer clamp, looks like the right-sized fix to me. I checked that the grace check uses wall time (get_duration_usec() measures from the start time), not m_cur_stats.m_second, so it fires even when no op ever completes. I also checked that a disconnect moves the retry queue into the replay queue (shard_connection.cpp ~L651), so holds_retries() stays false for a client that is only waiting to reconnect. That fits the new test_test_time_reconnecting_client_left_alone_retry_on_error. The regression test fails on master and passes here, and it pins rc, the JSON duration and the failed-keys count, which is the bar we want for this kind of fix.

A couple of questions, neither blocking:

  • I may be missing something, but in cluster mode, what happens to a client where one shard connection is reconnecting (requests in m_replay_queue) while another shard still holds retries? all_connections_idle() is true and one connection holds retries, so I think the whole client gets ended. disconnect_and_abandon_held() would then abandon the reconnecting shard's replay queue too, and those requests would be counted under "were still retrying" even though they were waiting for a reconnect. Since the grace is already over, ending the client is probably fine. I'm only wondering whether the message and the README's "left alone while reconnecting" wording still hold there. The new test calls skipOnCluster(), so nothing covers this. Whoever owns the cluster reconnect paths might want to take a second look.
  • The stall warning on stderr is now two lines instead of one. That isn't a JSON or schema change, so I don't see a compat problem. Did you check whether any CI or scripts grep for the old single line beyond the two test files updated here?

The core fix looks solid to me. I'd just like the cluster mixed-state question answered before this merges.

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

@fcostaoliveira fcostaoliveira changed the title End a --retry-on-error --test-time run at its deadline when nothing completes End a --retry-on-error --test-time run whose retries never succeed after the drain grace Oct 16, 2026
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Replies point by point. The branch is now at 9b89460, rebased on ec4e6fa, and the design changed.

  1. Overshoot by one retry backoff. You were right. The first version only noticed the deadline when a reply came in, so a long backoff held the run: a 20000 ms backoff with --test-time 3 ended at 20 s. The wall-clock finished() also broke test_moved_after_test_time_refreshes_slots in CI. That test pins an existing contract: retries go on after --test-time, and a MOVED that arrives then still refreshes the slot map.

    So the fix no longer touches finished(). A run like this is now ended by End a --test-time run whose server stops replying (10 s drain grace) #669's drain grace, which exists to bound runs that keep going after the deadline. abandon_unanswered_requests() used to skip a client with no reply pending, so it missed one whose requests were all held in the retry queue. It now ends that client 10 s after the deadline as well: the held requests are counted as errors (run-ended-before-resend), and the reported end time is start + --test-time.

    The grace check comes from the main thread's 1 s tick (event_base_once into the worker loop), so the backoff can no longer delay the end. Every case (factor 0/1/2, a 20 s backoff, and a 1000 ms × 2 backoff) ends at test_time + 10 s + about 1 s, with JSON Total duration = test_time. I did not clamp the drain timer: with the tick-driven grace it adds nothing, and a timer clamped to the grace instant would spin until the tick arrived.

  2. 4.0 s vs 3.0 s. That is the main thread's sleep(1) poll for worker completion, not a delay in the run. The JSON duration of the same runs is about test_time (3001 to 3036 ms), and a 0 ms backoff ended at 3.0 s wall. The PR body says so now.

  3. Backoff longer than the remaining test time. Added a 20000 ms case with --test-time 3. The test now also:

    • times runs with time.monotonic();
    • checks lower and upper bounds on elapsed time (test_time + 10 <= elapsed < test_time + 12.5);
    • checks JSON Total duration ≈ test_time;
    • checks the held for retry ... counted as errors count against the failed-keys run-ended-before-resend rows;
    • includes a control without --retry-on-error that must end at --test-time.

    It fails on bc7320a (every retry case still running at the 23 s kill) and passed 5/5 on the branch.

On #666: this PR no longer touches finished(), run_is_over() or run_deadline(). It only extends #669's abandon path, so the two deadline notions are unchanged.

…ter the drain grace

With --retry-on-error, unlimited --max-retries and a server that rejects
every request (e.g. -OOM), a --test-time run never ended.
client::finished() measures the run with the per-second stats clock, which
only moves on a completed op, and a reply handed to enqueue_retry()
completes none. #669's drain grace is meant to bound exactly this kind of
run, which keeps going after the deadline, but
abandon_unanswered_requests() returned early for a client with no reply
pending, and a request held in the retry queue for its backoff is not
pending. With --pipeline 1 that is almost always the case. Since 50cfd7f
resumes a paused connection to send a retry, such a run resends its
retries forever on master.

Count a client that still holds retries as unanswered too.
TEST_TIME_DRAIN_GRACE_SECS after the deadline it is ended like a stalled
one: the held requests are counted as errors (failed-keys status
run-ended-before-resend), and the reported end time is start +
--test-time, so Runtime and the rates cover --test-time.

handle_end_stalled_clients() now reports the two kinds of client
separately, by what each one had: "N client(s) got no reply to M
request(s)" for clients waiting for replies, and "N client(s) were still
retrying M request(s)" for clients holding retries, once per thread
rather than one "held for retry" line per client. A client with both
(the tick found a resend on the wire) is in both lines.

Retries still go on after --test-time, as before, so a MOVED that arrives
then still refreshes the slot map
(test_moved_after_test_time_refreshes_slots). The grace check runs from
the main thread's 1 s tick, so a long retry backoff cannot hold the run
past it. A client waiting for a reconnect is still left alone, with or
without --retry-on-error: its requests wait in the replay queue.

README, man page and --help describe the new end of such runs.

Fixes #715

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

Copy link
Copy Markdown
Collaborator Author

Thanks. Replies to the second review, point by point. The branch is now at 602a6af, rebased on e09ee54.

(a) Description vs code. The PR body is rewritten for the grace-based design. That includes the decision, the before/after table, the #666 overlap, a one-line dependency note for the server-dies-under---reconnect-on-error case (#656, fixed by #666), and the change from exit 2 at --connection-stage-timeout to exit 0 at test_time + 10 s.

(b) Clock moved by another connection. Yes, finished() becomes true at --test-time in that case. It does not end the client there, though. Under the existing contract (test_moved_after_test_time_refreshes_slots), retries continue after the deadline while requests are in flight, so the client keeps retrying until the drain grace ends it. This is the same path as when nothing completes. The sem and life review lenses measured it on 9b89460: the run ends at test_time + grace, and the reported duration is clamped to --test-time. The extended path is reached whenever a client still holds retries 10 s after the deadline, whether or not anything completed.

(c) Mixed clients in one warning. Fixed. handle_end_stalled_clients() now classifies each client by what it actually had and prints two separate lines per thread:

  • N client(s) got no reply to M request(s) ... for clients with pending replies;
  • N client(s) were still retrying M request(s) ... ended them (counted as errors, not resent). for clients holding retries.

A client with both is counted in both. The per-client "held for retry" lines are folded into the second line, so -t 2 -c 8 prints 2 lines instead of 16. The reconnect-left-alone test now asserts that neither warning appears. A new --retry-on-error variant also checks that a client waiting for a reconnect is not treated as retrying.

(d) Test length and bounds. Trimmed to factor 0, factor 2, the 20 s backoff and the control, about 45 s in total. The upper bound is now test_time + grace + 3 s, which leaves room under sanitizers: cluster ASan measured 15.02 s on the old 15.5 s bound. The test also accepts the case where the 1 s tick finds a resend on the wire. That client then appears in the "no reply" line, and the test checks that the two counts add up against the failed-keys rows, JSON Unanswered requests and the errors total.

(e) Hard-coded grace. The grace is now read back from the warning text, as test_test_time_stalled_server.py does, with 10 only as the upper bound.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Answering the two questions in the 18:59 version of the review:

  1. Cluster: one shard reconnecting while another holds retries. Once any connection of a client holds retries past the grace, the whole client is ended, and its sibling's replay queue (requests waiting for that sibling's reconnect) is abandoned with it. Those requests are counted as errors under run-ended-before-resend and appear in the "were still retrying" count, although strictly they were waiting for a reconnect. I think ending the client is right: it can't finish anyway, and the grace bounds the run. Only the label is approximate for that sub-case. I'd rather not add a third category and a third warning line here. The totals (errors, failed-keys rows, JSON) stay exact.
  2. Scripts or CI grepping the old single warning line: the only in-repo consumer is tests/test_test_time_stalled_server.py, which this PR updates. The "got no reply to N request(s)" line from End a --test-time run whose server stops replying (10 s drain grace) #669 is unchanged; the "were still retrying" line is new. I've also corrected the description: the warning prints at most two lines per thread per 1 s tick, because clients can cross the grace on different ticks.

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