Skip to content

End a --test-time run whose server stops replying (10 s drain grace) - #669

Merged
fcostaoliveira merged 5 commits into
masterfrom
fix-657-drain-timeout
Oct 16, 2026
Merged

fcostaoliveira merged 5 commits into
masterfrom
fix-657-drain-timeout

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Decision for maintainers: once --test-time has expired, memtier now waits at most 10 s (TEST_TIME_DRAIN_GRACE_SECS, a constant, no new flag) for replies to requests already sent. After that, the unanswered requests are abandoned: they are counted as errors, logged to --failed-keys-file (status no-reply-after-test-time), and reported as "Unanswered requests" in the JSON Runtime section next to "Interrupted". A warning is printed and the run ends and reports normally with exit code 0. The reported window is --test-time, not the grace period. The behavior is documented in the README, --help and the man page. If you'd prefer it configurable (e.g. --drain-timeout), or prefer a non-zero exit for this case, either is a small follow-up.

Problem

If the server stops answering while requests are in flight, a --test-time run never finishes. After the deadline it stops sending, then waits for the outstanding replies with no timeout. The process has to be killed, so no final report is printed and the results from the part of the run that worked are lost (#657).

redis-server --port 41500 --save "" --daemonize yes
memtier_benchmark -p 41500 --test-time 5 -c 2 -t 1 --hide-histogram --ratio 1:1 &
sleep 2; redis-cli -p 41500 client pause 600000 all

Root cause

  • fill_pipeline() stops sending once finished() is true. The run ends only from the "done" check, which needs m_pending_resp == 0. Nothing bounds that wait, and --connection-timeout only covers the connect.
  • While no replies arrive, the client's finished() isn't even re-evaluated, because get_duration() advances only when stats are updated. run_benchmark() waits for the threads with no deadline.

Fix

  • In run_benchmark(), the main thread already ticks once a second. Once --test-time + 10 s has passed since launch, each tick it calls client_group::end_stalled_clients() on every worker that is still running. That call does an event_base_once on the worker's base (safe across threads with evthread_use_pthreads()), so the work runs on the worker's own loop and also wakes it from an idle poll.

  • On the worker, client::abandon_unanswered_requests() ends any client whose own duration is past test_time + grace and that still has replies pending (!all_connections_idle()). It:

    • drops its pending requests (new shard_connection::drop_pending_requests()). Each workload request is logged to --failed-keys-file as no-reply-after-test-time and counted as an error and in the new Unanswered requests counter. This follows the existing run-ended-before-resend path in client::disconnect_all(). Setup commands are dropped but not counted. With --retry-on-error, the requests are not also held for a resend and counted again;
    • stamps the end time at start + test_time, so ops/sec covers the requested window and is not diluted by the grace period;
    • disconnects.

    The loop then runs out of events and the run reports as usual.

  • In staircase mode the step timer is freed once stalled clients are ended, so it cannot keep the loop alive until the next step.

  • run_stats gets m_unanswered_requests (summed when client, thread and run stats are merged) and a get_start_time() accessor. request_type_to_name() in client.cpp is no longer static, so shard_connection can name the command in the failed-keys row.

Scope and relation to #656: clients with nothing in flight are not touched. A client stuck reconnecting to a dead server (--reconnect-on-error with unlimited attempts, #656) is owned by a separate fix in the reconnect timer code (#666). This PR does not touch the reconnect scheduling, so the two changes are independent. A test now checks that a reconnecting client is left alone. --requests runs are unchanged: they have no deadline to measure a grace period from, so a general per-request timeout would be a separate feature.

Interaction with #661: #661 (open) adds connections_manager::abandon_requests() and shard_connection::abandon_replay_requests(). This PR does not depend on it. Whichever of the two lands second should switch drop_pending_requests() and its accounting to the shared helper.

Normal runs are unaffected. The check only fires 10 s after the deadline, on threads that have not ended (a plain --test-time 3 run still takes ~4 s wall time, as before). The JSON Runtime section gains one field, "Unanswered requests", which is 0 in a normal run.

Test evidence

tests/test_test_time_stalled_server.py has four cases. The stalled cases are 3 s all-SET runs with 2 threads. CLIENT PAUSE 600000 WRITE is sent on every master at 1.5 s, so the connections stay open but no SET is answered, and the test lifts it with CLIENT UNPAUSE at the end.

  • test_test_time_ends_when_server_stops_replying (2×2 clients): memtier exits 0 within test_time + 10 + 10 s. The warnings cover all 4 clients. The number of no-reply-after-test-time rows in --failed-keys-file and the JSON Unanswered requests both equal the abandoned count from the warnings, and nothing else is in the file. JSON Total duration < test_time + 2 s.
  • test_test_time_stalled_server_retry_on_error: the same checks. In addition, the final progress-line errors N equals the abandoned count (each request is counted exactly once), and the "held for retry" warning is absent.
  • test_test_time_stalled_server_staircase: --clients-start=1 --clients-step=1 --step-duration=60, so the next step is due long after the deadline. The 2 active clients are ended, and the run ends in time.
  • test_test_time_reconnecting_client_left_alone: CLIENT KILL TYPE normal at 1.5 s with --reconnect-on-error --reconnect-backoff-factor=15, so the reconnect is due after the grace period. No stall warning may be printed, and the run must last past test_time + 10 s (it ends through the reconnect).

Mutation check (each mutant built and run against the full file, oss):

binary result
previous head b1e6307 (rebased) 3 of 4 FAIL (no failed-keys rows, no Unanswered requests)
M1: drop m_stats.inc_error() in abandon_unanswered_requests() retry case FAIL (errors 0 ≠ abandoned)
M6b: drop event_free(m_staircase_timer) in handle_end_stalled_clients() staircase case FAIL (hung, killed: -9)
M8: drop the all_connections_idle() early return reconnect case FAIL (1 client(s) got no reply to 0 request(s) on both threads)
this PR (9cbcba4, on master 6eedafb) PASS: oss 5/5 runs (4/4 cases each; 3 of them before the rebase), oss-cluster 3 shards 2/2 runs after the reconnect-case wait was raised to 60 s

On the first push, origin/master (0298524 / 66b58e7) failed the stalled cases on oss and oss-cluster (hung, killed). In cluster mode, the reconnect case sometimes needs a second 15 s backoff round (about 32 s instead of 17 s). origin/master shows the same timing, so that case waits up to 60 s.

Not killed by a test: removing dec_reqs_generated() in drop_pending_requests(). That counter matters only for --requests runs, which this path never ends.

Affected versions

1.0.0 through 2.5.2 (latest) and master.

  • No reply timeout has ever existed. In 1.0.0 the run already ended only once the pipeline drained (client::fill_pipeline() / finished()). The current "no pending responses" end check came in 1c6735f "Enable arbitrary commands to be run on cluster mode" (Enable arbitrary commands to be run on cluster mode #117), with the same semantics.
  • Confirmed by running: master 3b3c2d7 (killed at 62 s); 2.5.2 (at 520% when killed at 27 s); master 0298524 (this PR's original base, via the regression test).
  • Derived from history: 1.0.0–2.5.1.

Fixes #657

🤖 Generated with Claude Code


Note

Medium Risk
Changes benchmark shutdown and error accounting for time-limited runs when servers stall; normal completions are unaffected until after the grace window, but slow legitimate replies past 10s are abandoned like missing replies.

Overview
Fixes hung --test-time runs when the server stops answering in-flight requests by capping the post-deadline drain at 10 seconds (TEST_TIME_DRAIN_GRACE_SECS).

After test_time + 10s from benchmark launch, the main thread asks each still-running worker to call end_stalled_clients(), which ends clients that still have pending replies: pending workload requests are dropped via shard_connection::drop_pending_requests(), logged to --failed-keys-file as no-reply-after-test-time, counted as errors (without double-counting under --retry-on-error), and summed in a new JSON Runtime field Unanswered requests. The client’s reported end time is clamped to start + test_time so throughput metrics exclude the grace wait; stderr warns and the process still exits 0. Staircase ramp timers are torn down so they cannot keep the event loop alive. Clients with nothing in flight (e.g. waiting on reconnect) are left alone.

README, --help, and the man page document the behavior; tests/test_test_time_stalled_server.py covers pause, retry-on-error, staircase, and reconnect cases.

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

@github-actions

github-actions Bot commented Oct 15, 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. I went through the diff and the tests. The approach looks sound to me: the main thread only decides when to start asking, and the actual teardown runs on the worker's own loop via event_base_once. Each client checks its own duration, which uses ts_diff_now(), so it keeps advancing during a stall. Dropping pending requests before disconnect_all() keeps --retry-on-error from counting them twice. Your mutation table (M1/M6b/M8) shows each test case catches the specific bug it is meant to catch, which is what I'd want for a change to error accounting and JSON output.

On the decision you asked about, a few thoughts:

  • I wonder if a fixed 10 s is safe for blocking commands. Someone running --command="BLPOP __key__ 30" or XREAD BLOCK 20000 ... can now get legitimate replies counted as errors and logged as no-reply-after-test-time, depending on when the deadline falls. The README covers this, but it reads more like a caveat than a fix. I'd lean toward keeping the constant for now rather than adding a flag. Did you consider whether the grace should at least not count those as errors, or whether a --drain-timeout is cheap enough to include here instead of as a follow-up? I'm not sure the extra flag is worth it, so this is a genuine question, not a block.
  • The new "Unanswered requests" key is additive and sits at the end of Runtime, so I don't see a compat problem for JSON consumers. Just checking: is it intentional that the text report has nothing for this case? Someone reading only stdout sees a higher error count but has no way to tell it apart from server-side errors unless they also watch stderr.
  • I'm fine with exit code 0 here, since the --test-time window was measured and reported. If CI users start relying on this path to detect a hung server, a non-zero exit could come later.

Nitpicking: after the grace period the main thread queues one event_base_once per still-running thread every tick until that thread finishes. It's harmless as far as I can tell, just mentioning it in case it ever runs alongside a long staircase/reconnect tail.

The core fix looks solid to me. I'd mainly want someone who uses blocking --command workloads to weigh in on the fixed 10 s before this merges.

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

@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 2 potential issues.

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 c763c83. Configure here.

Comment thread client.cpp Resolved
Comment thread client.cpp Resolved
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. I rebased onto 66b58e7 and pushed b1e6307. Point by point:

  1. --retry-on-error double count. Confirmed: one stalled request was counted twice and also produced the "held for retry … not resent" warning. abandon_unanswered_requests() now drops the pending requests itself first, through a new shard_connection::drop_pending_requests(), and then disconnects. disconnect() therefore has nothing left to move into the replay queue. Requests that were already waiting in a retry backoff queue are still accounted for by disconnect_all() as before, since they are separate requests. There is a new test, test_test_time_stalled_server_retry_on_error. It fails on the previous head c763c83 (the "held for retry" warning is printed) and passes now.
  2. Setup commands counted as errors. Fixed by the same change: drop_pending_requests() deletes the setup commands but counts and uncounts (dec_reqs_generated) only workload requests.
  3. Exit code. I kept 0. The run did measure the requested --test-time window, and the report covers exactly that window. The abandoned requests appear in the error count and in the stderr warning. This is the same behavior as the existing "held for retry … counted as errors" path at the end of a run. I'm happy to switch to a non-zero exit if a maintainer prefers that contract.
  4. Grace constant duplicated in the test. The test now reads the grace seconds from the warning line and uses the Python constant only as an upper bound for the wait. It also checks that all 2×2 clients were ended.
  5. Deadline comment. I added a note that each client checks its own deadline (its own start, or the staircase start), so a client that connected late is ended a tick or two later, and that this is intended.

Also changed:

  • Bugbot, staircase timer. The step timer is now freed when stalled clients are ended.
  • Test speed. The test now pauses only writes (CLIENT PAUSE WRITE with an all-SET workload). That way CLIENT UNPAUSE works and each case takes about 14 s, instead of about 27 s waiting for a bounded PAUSE ALL to expire. The two cases together take about the same time as the old single test, which matters for the TLS jobs that are close to their time limit (CI: standalone TLS test jobs now take ~25 min and hit the 25-minute "Run tests" limit #679).

Local results: both tests PASS 3/3 on oss and 3/3 on oss-cluster (3 shards). On origin/master 66b58e7 both FAIL (hang, killed). On c763c83 the retry case FAILS and the base case passes.

CI on c763c83: the three failures ("Test OSS TCP TLS v1.2", "Test OSS TCP TLS v1.3", "Test Single Endpoint: TCP TLS") were all the 25-minute "Run tests" limit from #679. In each log, test_test_time_stalled_server itself passed.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Replying to the automated review, point by point. I rebased onto 6eedafb and pushed 9cbcba4.

  1. --failed-keys-file. Agreed, the two "abandoned at end of run" paths should behave the same. drop_pending_requests() now logs every abandoned workload request as <ts>,<CMD>,<key>,no-reply-after-test-time,<retries>, with the command name from request_type_to_name(), which is no longer static. Setup commands are still dropped without a row. The tests check that the number of these rows equals the abandoned count, and that the file contains nothing else.

  2. Exit code. I kept 0, but the stall is now visible in the report. Before, the "counted as errors" in the warning pointed at a count that no final output showed: the error count only appears in the live progress line with --retry-on-error, and in Prometheus. The JSON Runtime section now has "Unanswered requests": N next to "Interrupted". It is 0 in a normal run and summed across clients, threads and runs. A harness can check that field, the same way it checks Interrupted. I kept rc=0 because the --test-time window was measured and is reported correctly, and because Interrupted (Ctrl+C) also exits normally. Switching to non-zero would make every CI job that hits a slow tail fail without its report being looked at. I agree this is a policy call and have left it as an open question for a human maintainer at the top of the PR body. Making it non-zero is a one-line change if that's preferred.

  3. The fixed 10 s. Now documented in the README (new "End of a --test-time run" section, which names the slow --command / Lua case), in --help, and in the man page (only the --test-time entry changed). The README explains where the abandoned requests are reported. I didn't add a flag. If a maintainer wants --drain-timeout, it's a small follow-up on top of the constant.

  4. waiting loop. It is equivalent, so it is replaced by if (all_connections_idle()) return 0;.

  5. One event_base_once per tick for a thread kept alive by something else. Yes, that's intended and harmless: the callback goes over the clients, skips ended ones and ones with nothing in flight, and returns. There is now a test for that case (test_test_time_reconnecting_client_left_alone). A client waiting for a reconnect scheduled after the grace period is left to the reconnect logic and is not ended as "no reply".

Also from review:

  • New staircase case (--step-duration=60, longer than test_time + 10): without the event_free(m_staircase_timer) the run hangs until the next step.
  • The --retry-on-error case now asserts that the final errors N equals the abandoned count, so removing the inc_error() is caught.
  • Each of those three mutants (no inc_error(), no staircase event_free, no idle check) now fails a test. The current head passes 5/5 runs on oss and 2/2 on oss-cluster (3 shards). Details are in the PR body.
  • Count requests dropped at reconnect under --retry-on-error as errors #661 adds a shared abandon_requests() helper. This PR doesn't depend on it. Whichever lands second should switch to it, as noted in the body.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

On the open review question (can a thread finish and have its base freed while an end_stalled_clients() once-event is still queued): no. end_stalled_clients() only posts event_base_once while the thread's m_finished is false. The event base is freed only in ~cg_thread / ~client_group, after the main thread's join(). With libevent 2.1 (2.1.12 here), event_base_free() also frees any once-event still pending, so the callback cannot run on freed memory. Reviewers checked this under TSan and ASan+UBSan and got no reports, standalone and in cluster mode.

Also in this push (3de0677, rebased on master 0062e56): the "End of a --test-time run" README section moves under "Using memtier_benchmark". It had been sitting between the read-preference section and its "Testing limitations" note.

fcostaoliveira and others added 5 commits October 16, 2026 11:16
After the --test-time deadline a connection stops sending and the run
ends only once every in-flight reply has arrived. Nothing bounded that
wait, so a server that accepts but never answers (CLIENT PAUSE, a hung
or partitioned node) kept memtier running forever and no report was
printed, losing the results of the part of the run that did work.

Give in-flight replies a 10 s grace period past the deadline. The main
thread, which already ticks once a second, asks each still-running
worker (via event_base_once, so the work runs on the worker's own loop)
to end any client that is that far past its deadline and still has
replies pending. Such a client counts its unanswered requests as
errors, stamps its end time at start + --test-time so the rates cover
the requested window and not the grace period, and disconnects; the
run then ends and reports as usual, with a warning.

Clients with nothing in flight are left alone: a client waiting for a
reconnect is #656 and is handled separately. --requests runs keep
waiting, as there is no deadline to measure a grace period from.

Fixes #657

Co-Authored-By: Claude Opus 5.5 <[email protected]>
abandon_unanswered_requests() counted every pending reply as an error and
then called disconnect_all(). With --retry-on-error, disconnect() moved
those requests into the replay queue, and disconnect_all() counted them
again and printed its "held for retry" warning. Drop the pending requests
first (shard_connection::drop_pending_requests()), counting only workload
requests, so setup commands in flight are not counted as errors either.

Also remove the staircase step timer when a stalled client is ended, so
it does not keep the loop alive until the next step, and test the
--retry-on-error case. The test now pauses only writes (CLIENT PAUSE
WRITE with an all-SET workload), so CLIENT UNPAUSE works and each case
takes ~14 s instead of waiting for a bounded PAUSE ALL to expire.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Requests dropped because no reply came within 10 s after --test-time
were counted as errors, but that count shows up in no final output, and
unlike the run-ended-before-resend path they never reached
--failed-keys-file.

- Log each abandoned workload request to --failed-keys-file with status
  "no-reply-after-test-time".
- Report the count as "Unanswered requests" in the JSON Runtime section,
  next to "Interrupted". The exit code stays 0: the --test-time window
  was measured and reported.
- Document the fixed 10 s grace in README, --help and the man page.
- Use all_connections_idle() instead of an open-coded loop.

Tests: assert the JSON count, the failed-keys rows and (with
--retry-on-error) the final error count; add a staircase case whose next
step is due long after the deadline, and a case where a client waiting
for a reconnect with nothing in flight must be left alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mark"

It sat between the cluster read-preference section and its "Testing
limitations" note.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts()

#661 added connections_manager::abandon_requests() as the single path for
"uncount and count as an error". Use it in drop_pending_requests() instead
of dec_reqs_generated() plus a separate inc_error() loop, so every
give-up site counts the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira merged commit 8f5fa34 into master Oct 16, 2026
129 checks passed
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
- test_live_server_drop_after_deadline_resends_held_requests: a proxy
  holds the replies from just before the deadline and drops the
  connections just after it; with --retry-on-error the drop is
  reconnected and the held requests are answered, none abandoned. It fails
  if a drop after the deadline is treated like a failed connect.
- The dead-from-the-start test asserts that --test-time did not end the
  run (no connection reached steady state), and honor_test_time makes more
  than 10 attempts (--reconnect-backoff-factor=0.7), so the
  --requests-only warning check can fail.
- Wall-clock bounds in the new tests are widened under sanitizers.
- count_connection_error() keeps "every failed connect counts" in one
  place; comments on the rejected-setup pre-set and the reconnect() < 0
  stop say why they are still needed.
- test_test_time_reconnecting_client_left_alone (#669): the reconnect is
  now due at the deadline, so the run ends well before the grace period.
- README: a peer that closes connections after a delay can extend the run
  by up to about twice that delay.

Refs #656

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
…rver

With --reconnect-on-error and unlimited --max-reconnect-attempts, a server
that goes away for good kept a --test-time run reconnecting forever, with
no report: the reconnect path never checked whether the run was over, and
finished() is otherwise only checked when requests are sent or answered.
A reconnect armed before the deadline also waited out its full backoff
(up to 60 s) and the report counted that dead time.

- run_deadline() / run_is_over(): the stop condition in one place. A
  started client is timed from its own start, also on the wall clock; a
  client that never started, once any connection reached steady state, from
  the benchmark's start (#667's contract, which this extends).
- next_reconnect_delay() caps the armed delay at the time left, on a local
  copy, so the backoff schedule is unchanged.
- stop_reconnecting_if_run_over(): when a connect fails and the run is over,
  stop reconnecting; a started client's stats end at the deadline, so the
  duration and throughput reflect --test-time. The deadline wins over a
  finite --max-reconnect-attempts.
- A drop of an established connection after the run is over gets one
  reconnect, so held replays are resent; a second drop counts as a failed
  connect (a peer that accepts and closes would otherwise loop at 0 s).
- Failed reconnects that never reach the event loop (unix socket) are
  counted as connection errors (count_connection_error()).
- With --requests and unlimited attempts, warn every 10 attempts that the
  server is still unreachable.
- A cluster dial that fails after the run is over leaves the connection
  dead instead of ending the client inside the CLUSTER SLOTS handler.
- README, --help and the man page document the behaviour; new tests in
  test_reconnections.py cover it, including a reconnect still connecting
  when #669's drain grace expires (its idle-client guard).

Fixes #656

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
…rver

With --reconnect-on-error and unlimited --max-reconnect-attempts, a server
that goes away for good kept a --test-time run reconnecting forever, with
no report: the reconnect path never checked whether the run was over, and
finished() is otherwise only checked when requests are sent or answered.
A reconnect armed before the deadline also waited out its full backoff
(up to 60 s) and the report counted that dead time.

- run_deadline() / run_is_over(): the stop condition in one place. A
  started client is timed from its own start, also on the wall clock; a
  client that never started, once any connection reached steady state, from
  the benchmark's start (#667's contract, which this extends).
- next_reconnect_delay() caps the armed delay at the time left, on a local
  copy, so the backoff schedule is unchanged.
- stop_reconnecting_if_run_over(): when a connect fails and the run is over,
  stop reconnecting; a started client's stats end at the deadline, so the
  duration and throughput reflect --test-time. The deadline wins over a
  finite --max-reconnect-attempts.
- A drop of an established connection after the run is over gets one
  reconnect, so held replays are resent; a second drop counts as a failed
  connect (a peer that accepts and closes would otherwise loop at 0 s).
- Failed reconnects that never reach the event loop (unix socket) are
  counted as connection errors (count_connection_error()).
- With --requests and unlimited attempts, warn every 10 attempts that the
  server is still unreachable.
- A cluster dial that fails after the run is over leaves the connection
  dead instead of ending the client inside the CLUSTER SLOTS handler.
- README, --help and the man page document the behaviour; new tests in
  test_reconnections.py cover it, including a reconnect still connecting
  when #669's drain grace expires (its idle-client guard).

Fixes #656

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
…rver

With --reconnect-on-error and unlimited --max-reconnect-attempts, a server
that goes away for good kept a --test-time run reconnecting forever, with
no report: the reconnect path never checked whether the run was over, and
finished() is otherwise only checked when requests are sent or answered.
A reconnect armed before the deadline also waited out its full backoff
(up to 60 s) and the report counted that dead time.

- run_deadline() / run_is_over(): the stop condition in one place. A
  started client is timed from its own start, also on the wall clock; a
  client that never started, once any connection reached steady state, from
  the benchmark's start (#667's contract, which this extends).
- next_reconnect_delay() caps the armed delay at the time left, on a local
  copy, so the backoff schedule is unchanged.
- stop_reconnecting_if_run_over(): when a connect fails and the run is over,
  stop reconnecting; a started client's stats end at the deadline, so the
  duration and throughput reflect --test-time. The deadline wins over a
  finite --max-reconnect-attempts.
- A drop of an established connection after the run is over gets one
  reconnect, so held replays are resent; a second drop counts as a failed
  connect (a peer that accepts and closes would otherwise loop at 0 s).
- Failed reconnects that never reach the event loop (unix socket) are
  counted as connection errors (count_connection_error()).
- With --requests and unlimited attempts, warn every 10 attempts that the
  server is still unreachable.
- A cluster dial that fails after the run is over leaves the connection
  dead instead of ending the client inside the CLUSTER SLOTS handler.
- README, --help and the man page document the behaviour; new tests in
  test_reconnections.py cover it, including a reconnect still connecting
  when #669's drain grace expires (its idle-client guard).

Fixes #656

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
…rver

With --reconnect-on-error and unlimited --max-reconnect-attempts, a server
that goes away for good kept a --test-time run reconnecting forever, with
no report: the reconnect path never checked whether the run was over, and
finished() is otherwise only checked when requests are sent or answered.
A reconnect armed before the deadline also waited out its full backoff
(up to 60 s) and the report counted that dead time.

- run_deadline() / run_is_over(): the stop condition in one place. A
  started client is timed from its own start, also on the wall clock; a
  client that never started, once any connection reached steady state, from
  the benchmark's start (#667's contract, which this extends).
- next_reconnect_delay() caps the armed delay at the time left, on a local
  copy, so the backoff schedule is unchanged.
- stop_reconnecting_if_run_over(): when a connect fails and the run is over,
  stop reconnecting; a started client's stats end at the deadline, so the
  duration and throughput reflect --test-time. The deadline wins over a
  finite --max-reconnect-attempts.
- A drop of an established connection after the run is over gets one
  reconnect, so held replays are resent; a second drop counts as a failed
  connect (a peer that accepts and closes would otherwise loop at 0 s).
- Failed reconnects that never reach the event loop (unix socket) are
  counted as connection errors (count_connection_error()).
- With --requests and unlimited attempts, warn every 10 attempts that the
  server is still unreachable.
- A cluster dial that fails after the run is over leaves the connection
  dead instead of ending the client inside the CLUSTER SLOTS handler.
- README, --help and the man page document the behaviour; new tests in
  test_reconnections.py cover it, including a reconnect still connecting
  when #669's drain grace expires (its idle-client guard).

Fixes #656

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
…rver

With --reconnect-on-error and unlimited --max-reconnect-attempts, a server
that goes away for good kept a --test-time run reconnecting forever, with
no report: the reconnect path never checked whether the run was over, and
finished() is otherwise only checked when requests are sent or answered.
A reconnect armed before the deadline also waited out its full backoff
(up to 60 s) and the report counted that dead time.

- run_deadline() / run_is_over(): the stop condition in one place. A
  started client is timed from its own start, also on the wall clock; a
  client that never started, once any connection reached steady state, from
  the benchmark's start (#667's contract, which this extends).
- next_reconnect_delay() caps the armed delay at the time left, on a local
  copy, so the backoff schedule is unchanged.
- stop_reconnecting_if_run_over(): when a connect fails and the run is over,
  stop reconnecting; a started client's stats end at the deadline, so the
  duration and throughput reflect --test-time. The deadline wins over a
  finite --max-reconnect-attempts.
- A drop of an established connection after the run is over gets one
  reconnect, so held replays are resent; a second drop counts as a failed
  connect (a peer that accepts and closes would otherwise loop at 0 s).
- Failed reconnects that never reach the event loop (unix socket) are
  counted as connection errors (count_connection_error()).
- With --requests and unlimited attempts, warn every 10 attempts that the
  server is still unreachable.
- A cluster dial that fails after the run is over leaves the connection
  dead instead of ending the client inside the CLUSTER SLOTS handler.
- README, --help and the man page document the behaviour; new tests in
  test_reconnections.py cover it, including a reconnect still connecting
  when #669's drain grace expires (its idle-client guard).

Fixes #656

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
…rver

With --reconnect-on-error and unlimited --max-reconnect-attempts, a server
that goes away for good kept a --test-time run reconnecting forever, with
no report: the reconnect path never checked whether the run was over, and
finished() is otherwise only checked when requests are sent or answered.
A reconnect armed before the deadline also waited out its full backoff
(up to 60 s) and the report counted that dead time.

- run_deadline() / run_is_over(): the stop condition in one place. A
  started client is timed from its own start, also on the wall clock; a
  client that never started, once any connection reached steady state, from
  the benchmark's start (#667's contract, which this extends).
- next_reconnect_delay() caps the armed delay at the time left, on a local
  copy, so the backoff schedule is unchanged.
- stop_reconnecting_if_run_over(): when a connect fails and the run is over,
  stop reconnecting; a started client's stats end at the deadline, so the
  duration and throughput reflect --test-time. The deadline wins over a
  finite --max-reconnect-attempts.
- A drop of an established connection after the run is over gets one
  reconnect, so held replays are resent; a second drop counts as a failed
  connect (a peer that accepts and closes would otherwise loop at 0 s).
- Failed reconnects that never reach the event loop (unix socket) are
  counted as connection errors (count_connection_error()).
- With --requests and unlimited attempts, warn every 10 attempts that the
  server is still unreachable.
- A cluster dial that fails after the run is over leaves the connection
  dead instead of ending the client inside the CLUSTER SLOTS handler.
- README, --help and the man page document the behaviour; new tests in
  test_reconnections.py cover it, including a reconnect still connecting
  when #669's drain grace expires (its idle-client guard).

Fixes #656

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
…rver

With --reconnect-on-error and unlimited --max-reconnect-attempts, a server
that goes away for good kept a --test-time run reconnecting forever, with
no report: the reconnect path never checked whether the run was over, and
finished() is otherwise only checked when requests are sent or answered.
A reconnect armed before the deadline also waited out its full backoff
(up to 60 s) and the report counted that dead time.

- run_deadline() / run_is_over(): the stop condition in one place. A
  started client is timed from its own start, also on the wall clock; a
  client that never started, once any connection reached steady state, from
  the benchmark's start (#667's contract, which this extends).
- next_reconnect_delay() caps the armed delay at the time left, on a local
  copy, so the backoff schedule is unchanged.
- stop_reconnecting_if_run_over(): when a connect fails and the run is over,
  stop reconnecting; a started client's stats end at the deadline, so the
  duration and throughput reflect --test-time. The deadline wins over a
  finite --max-reconnect-attempts.
- A drop of an established connection after the run is over gets one
  reconnect, so held replays are resent; a second drop counts as a failed
  connect (a peer that accepts and closes would otherwise loop at 0 s).
- Failed reconnects that never reach the event loop (unix socket) are
  counted as connection errors (count_connection_error()).
- With --requests and unlimited attempts, warn every 10 attempts that the
  server is still unreachable.
- A cluster dial that fails after the run is over leaves the connection
  dead instead of ending the client inside the CLUSTER SLOTS handler.
- README, --help and the man page document the behaviour; new tests in
  test_reconnections.py cover it, including a reconnect still connecting
  when #669's drain grace expires (its idle-client guard).

Fixes #656

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
…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:
disconnect_all() counts the held requests as errors ("held for retry when
the run ended were not resent", failed-keys reason run-ended-before-resend)
and the reported end time is start + --test-time, so Runtime and the rates
cover --test-time. When only retries were left, say so instead of
"got no reply to 0 request(s)".

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.

Fixes #715

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
…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 added a commit that referenced this pull request Oct 16, 2026
…ter the drain grace (#724)

With --retry-on-error, a --test-time run whose requests kept failing
(e.g. an always-OOM server) never ended: the client always held requests
for retry, so it never looked idle, and the #669 drain grace skipped
clients with nothing pending. The run only stopped when killed, or at
--connection-stage-timeout with exit 2.

Retries still continue after --test-time (the contract pinned by
test_moved_after_test_time_refreshes_slots). The #669 drain grace now
also covers clients that hold retries: 10 s after the deadline such a
client is ended, its held requests are counted as errors and written to
--failed-keys-file with status run-ended-before-resend, and the reported
end time is clamped to start + test_time, so Runtime and the rates cover
--test-time.

Each client is classified by what it actually had, and the warning
prints at most two lines per thread per tick:
  N client(s) got no reply to M request(s) ... abandoned them
  N client(s) were still retrying M request(s) 10 seconds after the
  test time ended; ended them (counted as errors, not resent)
JSON "Unanswered requests" does not include held retries.

Docs (README, man page, --help) describe the new end-of-run case. An
always-failing run now exits 0 at test_time + 10 s, where master exited
2 at --connection-stage-timeout when that was shorter.

Tests: the #715 repro across backoff factors and a 20 s backoff, with a
control without --retry-on-error, cross-checking the warning counts
against failed-keys rows, JSON and the error total; and reconnect
left-alone cases (with and without --retry-on-error) asserting neither
warning appears.

Fixes #715

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 26, 2026
Once the run is over, end_client_after_run() leaves the client to a busy
sibling (siblings_done()), which since this PR includes a connect in
progress, so a redial's rejected AUTH still fails the run (#630). Without
--connection-timeout, a redial whose SYN is dropped (a firewalled or dead
node) then kept the run open for the kernel's connect timeout: with the
main connection's redial refused after the deadline, a 3 s run ended at
136 s, where master ended at 4 s.

end_client_after_run() now marks the client as waiting for its siblings,
and the drain grace ends such a client like one with replies pending, at
the deadline plus 10 s, with a "still waiting for a connection" warning.
A redial that connects within the grace keeps the #630 guarantee.
Single-endpoint clients have no siblings and are unchanged (#669's
idle-client guard).

Also widen the held-refresh transaction test's bound to test_time + 6.

Fixes #879
Fixes #880

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 26, 2026
ff07182 bounded the wait on a blackholed redial only when a connection
had tried to end the client after the run (end_client_after_run()). A
connection that stays up and idle past the deadline defers its end on
!siblings_done() in fill_pipeline() without marking the client, so the
drain grace still skipped it and the run waited for the kernel's connect
timeout (137 s for a 3 s run; 135 s on master). Without --rate-limiting
that connection is paused before the deadline and fill_pipeline() never
runs again, so marking the client from there cannot cover it.

The drain grace now also ends a client with a connection up and idle
(nothing it may send again) while another connection's connect is in
progress (client::idle_connection_waits_for_connect()). A sibling waiting
for its reconnect timer, or a client whose connections are all down, is
still left to the reconnect logic (#669). A redial that connects within
the grace still sends its AUTH (#630), and --connection-timeout, when
set, still ends the run sooner (5.0 s with 2).

Reported by Cursor Bugbot.

Fixes #879
Fixes #880

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.

Run hangs forever after --test-time when the server stops replying (no reply timeout)

1 participant