Repository navigation
Exit 2 when any --run-count run hits --connection-stage-timeout - #752
Conversation
With --run-count > 1, a connection-stage abort in a run other than the last one was lost: the series exited 0 (or 1 if another run failed), even though the aborted run is part of BEST/WORST/AGGREGATED and marks them Interrupted. main() read g_connection_stage_aborted once after the run loop, and connection_stage_supervisor_reset() clears it at the start of every run so that a run-1 abort does not suppress run 2's worker-failure report. So the flag only described the last run, while g_worker_failed (exit 1) is sticky across runs. Keep the per-run flag for the in-run logic and latch a separate g_any_run_connection_stage_aborted, set by the main thread next to it and never reset, which main() uses for the exit code. The existing precedence is kept: 2 wins over 1, now also when the abort and the failure happen in different runs. The remaining runs still start after an abort, as before. The new test drives a scripted RESP peer that decides per connection (one per run with -t 1 -c 1) whether a run completes, aborts on AUTH, or fails mid-run, and checks the exit code of each mix. Fixes #739 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two failures end memtier with exit(1) before main() returns: a thread that fails to prepare (for example a --unix-socket connect that fails) and a failed --reconnect-interval reconnect. In a later --run-count run they bypassed the any-run-aborted latch, so a series whose run 1 was aborted could still exit 1. Both now exit through failure_exit_code(), which returns 2 when an earlier run was aborted and 1 otherwise. The latch is now atomic, since a worker thread reads it. The test covers the prepare path with a scripted --unix-socket peer that removes its socket after run 1, and asserts that the drop runs really failed. The test skips cluster and TLS cells, since it only uses its own peer. README lists the --run-count rule with the other exit statuses, covers Ctrl+C after an aborted run, and notes that the aborted run still counts in AGGREGATED. --help and the man page say that an abort in any run exits 2. Refs #739 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the diff and the run loop in A few small things:
The core fix and the tests look solid to me. Only the release-note question seems worth answering before merge. |
….cpp shard_connection.cpp now calls failure_exit_code() from memtier_benchmark.cpp, which the unit tests do not link, so make check failed at link time. Add the stub next to the other main-owned stubs. Refs #739 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Point by point:
|
Problem
With
--run-count N, if a run other than the last one is aborted by--connection-stage-timeout, memtier exits 0 (or 1 if another run failed). The aborted run is still part of BEST/WORST/AGGREGATED, which the JSON marks"Interrupted": "true". Exit 2 was only returned when the last run aborted.Root cause
main()readg_connection_stage_abortedonce, after the run loop.connection_stage_supervisor_reset()clears that flag at the start of every run, so that a run-1 abort does not stay latched into run 2 and suppress its worker-failure report incg_thread_start(). The flag therefore described only the last run, whileg_worker_failed(exit 1) is never reset and covers every run.Fix
Keep the per-run flag for the in-run logic. Add
g_any_run_connection_stage_aborted, set by the main thread next to it inrun_benchmark()and never reset, and use it for the exit code.The two
exit(1)paths that can end a later run beforemain()returns now exit throughfailure_exit_code(), so they return 2 after an earlier abort. These are a thread that fails to prepare (for example a failed--unix-socketconnect) and a failed--reconnect-intervalreconnect. The latch is atomic because a worker thread reads it.The existing precedence is kept and now also applies across runs: 2 wins over 1, whether the abort and the worker failure (or output write error) happen in the same run or in different runs. This matches
test_connection_stage_abort_keeps_rc_2_on_write_error. The remaining runs still start after an abort, as before, and the aggregated output already flags the aborted run as Interrupted. README documents the exit status of a--run-countseries in the "Exit status" list, including Ctrl+C after an aborted run and the fact that the aborted run still counts in AGGREGATED.--helpand the man page say that an abort in any run exits 2.Tests
New
tests/test_run_count_exit_code.py. A scripted RESP peer decides per connection what happens. With-t 1 -c 1and no--reconnect-on-error, connection n is run n. A run either completes, rejects AUTH (the run aborts), or is closed after 9 replies (a worker failure, exit 1). The test checks the exit code and the abort count for each plan:"refuse" removes the
--unix-socketpath after the previous connection closes, so that run's thread prepare fails.The first plan also checks that AGGREGATED and WORST are
Interrupted: trueand BEST isfalse.Measured at the current head: 6 of 6 full runs of the file passed (9/9 tests each). On master (a7881e0), the same 4 tests failed. At the first commit 04ed3da, only the unix-socket abort test failed (rc 1). The test skips cluster and TLS cells because it only uses its own scripted server. These suites also pass with the fix:
test_cluster_slots_bad_reply.py(16),test_cli_validation_run_count.py(5),test_reconnect_late_server_start.py(2),test_reconnections.py(17), andtests_oss_simple_flow.py:test_connection_stage_abort_keeps_rc_2_on_write_error.I also ran the repro from the issue (
-OOMuntil the preloaded keys expire) with--run-count 3on master a7881e0. Run 1 aborted and the exit code was 0.The unit tests that link
shard_connection.cpp(cluster_hslot,cluster_transaction,retry_drain,run_stats_merge,socket_options) get anint failure_exit_code() { return 1; }stub next to their other main-owned stubs.make checkpasses locally (10/10).Merge note: open PR #666 adds
tests/unit/reconnect_siblings_test.cpp, which has the same stubs. Whichever of #666 and this PR merges second must add thefailure_exit_code()stub there as well, ormake checkfails at link time.Fixes #739
Release note
--run-count: if any run is aborted by--connection-stage-timeout, memtier now exits 2, even when a later run completed or failed. Before, only the last run counted, so such a series could exit 0 or 1. A series mixing an abort with a worker failure or output write error (which used to exit 1) now exits 2, the same precedence a single run already had. Scripts that treat 1 and 2 differently will see the new code for that mix.Affected versions
2.4.0 through 2.5.2 (latest) and master. Introduced by 2e8869e "fix(connection-stage): bound retry loop with --connection-stage-timeout (Refs #426 phase 1) (#431)", which added the flag, its reset per run and exit 2. The first tag that contains it is 2.4.0. Reproduced on master a7881e0.
🤖 Generated with Claude Code