Repository navigation
Resend requests after the setup ladder on a new connection - #613
Conversation
72e664e to
2e6ebd0
Compare
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the diff and the description. Moving the resend into
Nitpicking: The ordering fix looks solid to me. I'd mainly like an answer on (1) before merge, since it may change Duration and ops/sec for every (I'd file this as a comment, not a formal block.) |
With --retry-on-error, the requests in flight on a dropped connection are resent once it reconnects. handle_event() resent them as soon as the connection came up, before fill_pipeline() sent the setup commands (AUTH, SELECT, HELLO, READONLY, CLUSTER SLOTS). The server runs a connection's commands in order, so with --authenticate every resent request was answered -NOAUTH and counted as an error, and with --select-db it ran against database 0. fill_pipeline() already resends requests handed over from a retired connection only once the setup ladder is done. Let it handle the reconnect case too: when requests are waiting to be resent and the ladder is not done, send the ladder and return; the resends follow when its replies come in, still ahead of fresh work. This is done even after the run's stop condition is reached, as the resends are still owed a reply. Fixes #527 Co-Authored-By: Claude Opus 5.5 <[email protected]>
process_response() ended the run's stats as soon as the run was finished. Since the previous commit, a reconnect that lands after a --test-time deadline sends the setup ladder first and the resends only once its replies are in, so the stats ended on the SELECT or AUTH reply, with the resends not even sent. run_stats::set_end_time() reports the current second's bucket without rolling it, so the resends' replies went into a bucket that was never reported, and the next roll reported the end bucket a second time: Count fell short of the last progress line by the resent requests, and Connection Errors doubled. End the stats there only once every connection is idle, like the two other end-of-run checks do. Also test the cluster side of #527: reads resent to a replica before READONLY were answered -MOVED. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The deadline test only compared Count with the last progress line, which still held if the requests in flight were never resent once the run was finished. Count the SETs sent on the connections opened after the stall and expect every request that was in flight. fill_pipeline() checked the --transaction hold on CLUSTER SLOTS twice; give it a name. Drop a leftover comment in handle_event() and say which held requests are not resent at the end of a run, and when the transaction hold lets fresh work go ahead of resends. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2e6ebd0 to
24dfedf
Compare
|
Thanks for the review. Point by point:
🤖 Generated with Claude Code |
After the replay block was rewritten (#613), say directly which retries the fill_pipeline() drain is for. Pass --authenticate when the test cluster has a password, so the reconnect case also runs with AUTH. Co-Authored-By: Claude Opus 5.5 <[email protected]>
After the replay block was rewritten (#613), say directly which retries the fill_pipeline() drain is for. Pass --authenticate when the test cluster has a password, so the reconnect case also runs with AUTH. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With --retry-on-error, the requests in flight when the connection drops are held for replay until the setup ladder succeeds (#613). After a rejected AUTH that never happens, but the deadline check in handle_reconnect_timer_event() required an empty replay queue, so the run still reconnected forever (#625). Give up once the run is over regardless of held replays. If no reply is pending, disconnect_all() ends the client and counts the held requests as run-ended-before-resend errors. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ing (#630) * Reconnect when a setup step fails on a reconnect With --reconnect-on-error, if the server's password changes mid-run and the connections are then dropped, memtier reconnects, logs "Reconnection successful", gets -WRONGPASS for AUTH, and hangs until killed. --test-time, --requests and --max-reconnect-attempts are all ignored. An AUTH, SELECT or HELLO error reply only set error and returned from process_response(). The connection stayed open with its setup unfinished, so no workload request was ever sent on it again, and the --test-time and --requests checks, which run when requests are sent or answered, were never reached. --connection-stage-timeout does not help either: it stops checking once the run has reached steady state. A wrong password at startup only ends because of it. With --reconnect-on-error, handle a setup error like a dropped connection, as READONLY errors already are: attempt_reconnect() disconnects and schedules the next attempt, so --max-reconnect-attempts bounds it. Without the option, startup is unchanged. With unlimited attempts, the reconnect timer now leaves the connection disconnected once the run is finished (and nothing is held for replay), so the thread ends at --test-time and the run fails as incomplete instead of reconnecting forever. "Reconnection successful" was logged when the TCP connect was started, before the setup ladder ran. Log it on the first successful response after the setup ladder, where the attempt counter is already reset. Fixes #625 Co-Authored-By: Claude Opus 5.5 <[email protected]> * Stop reconnecting at the deadline only after a rejected setup step The previous commit left any connection disconnected when its reconnect timer fired after the run's deadline. A plain connection drop near the end of a --test-time run then left that client without an end time, and the run failed as incomplete (test_json_aggregated_connection_errors_sec and test_F17_monotonicity_under_churn in the sanitizer jobs). Before, the reconnect went through and the client ended on its first response. Only stop when the pending reconnect follows an AUTH/SELECT/HELLO rejection, which is the case that otherwise retries forever with unlimited attempts. The run then fails as incomplete, with a message saying why. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Set the test password after the TLS setup connections are opened Under TLS, add_required_env_arguments() opens new connections to the server to set tls-protocols. The AUTH tests set requirepass before it, so those connections failed with "Authentication required", outside the try/finally that clears the password, and every later test on the server failed the same way. Set requirepass right before memtier starts, inside the try. Clear it through a connection authenticated with the new password if the pool has to open one. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Stop reconnecting after a rejected setup even with replays held With --retry-on-error, the requests in flight when the connection drops are held for replay until the setup ladder succeeds (#613). After a rejected AUTH that never happens, but the deadline check in handle_reconnect_timer_event() required an empty replay queue, so the run still reconnected forever (#625). Give up once the run is over regardless of held replays. If no reply is pending, disconnect_all() ends the client and counts the held requests as run-ended-before-resend errors. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Check that held replays are counted when a rejected setup ends the run Without this, the test passed even if the timer path dropped the requests held for replay instead of handing them to disconnect_all(). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Problem
With
--retry-on-error --reconnect-on-error, the requests in flight on a dropped connection are resent once it reconnects. They were resent before the connection's setup commands (AUTH, SELECT, HELLO, READONLY, CLUSTER SLOTS). Redis runs a connection's commands in order, so:--authenticate, every resent request is answered-NOAUTHand counted as an error;--select-db, the resent requests run against database 0;Root cause
handle_event(BEV_EVENT_CONNECTED)calleddrain_replay_queue_after_reconnect()beforefill_pipeline(), andfill_pipeline()is the only place that sends the setup ladder.Fix
The drain in
handle_event()is removed. The resend now happens infill_pipeline(), which already had a drain gated onis_conn_setup_done()for requests handed over from a retired connection (#575):fill_pipeline()sends the ladder and returns.--transactionMULTI is open (Cluster --transaction: CLUSTER SLOTS sent inside an open MULTI wedges the main connection #569).What this leaves alone:
drain_replay_queue_after_reconnect()is unchanged, so the max-retries drops anddec_reqs_generatedwork as before.replay_request()is untouched, so its ASKING prefix applies the same way.Second commit: ending the stats at a
--test-timedeadlineAfter the first commit, a reconnect that lands after the deadline:
process_response()withfinished()already true, so it callsset_end_time();run_stats::set_end_time()reports the current second's bucket without rolling it. The resends' replies then went into a bucket that was never reported, and the next roll reported the end bucket a second time.Effect, with a proxy that stops replies at 1.8 s of
--test-time 2and closes at 2.1 s (-c 2 --pipeline 32, with-a pwor--select-db=3):process_response()now ends the stats only whenfinished() && all_connections_idle(), the same condition as the two other end-of-run checks (thefill_pipeline()"done" branch and the rate-limit timer). Measured with the same proxy:The server's SET calls are Count + 64, from the 64 requests that ran once and were resent after their replies were lost.
Behaviour change (release notes)
--test-timetotals now include the replies in flight at the deadline. Before, a client's stats ended at the first reply read after the deadline. Replies to requests still in flight, read later, were left out of the report. With deep pipelines that is noticeable:-c 4 -t 2 --pipeline 256 -d 4000 --test-time 3reported a Count 2008 short of the server'scmdstat_setcalls on master, in 2/2 runs. Now the stats end when every connection is idle. Count equals the server's count (0 short in 2/2 runs), and the duration runs to the last reply: 3010 ms instead of 3000 ms in that run. If a shard is slow to answer after the deadline, the duration stretches by that much too, and ops/sec reflects it. Before, those replies were not reported at all. A shard that never answers leaves the run waiting for that reply either way; that part is unchanged.--authenticate, resends are no longer counted as rejected operations. On master, every request resent after a reconnect was answered-NOAUTH, and those replies were counted in Count and Ops/sec (and as errors). Now the resends run after AUTH and are counted as normal operations.Third commit: review follow-ups
test_replays_after_deadline_are_countednow also counts, at the proxy, the SETs sent on the connections opened after the stall, and expectsclients * pipeline(64). The mutant that skips resends once the run is finished (!m_conns_manager->finished() &&added to the resend block infill_pipeline()) passed the old assertions. It now fails 5/5 with0 == 64"requests in flight were not resent"; this PR passes 5/5.--transactionhold on CLUSTER SLOTS, which was checked twice infill_pipeline(), is nowsetup_held_for_transaction().handle_event()is gone. Thefill_pipeline()comment now says which held requests are not resent when the run ends: those on a peer that is not connected (Count retries still queued when a --test-time run ends (#619) #620 accounts for those). It also says when the transaction hold lets fresh work go ahead of resends.Interaction with #620 (#619): #620 changes
client::disconnect_all(), which runs afterset_end_time()in thefill_pipeline()"done" branch. This PR doesn't touch that path or its order. The two only conflict textually intests/test_retry_on_error.py: both edit the imports and append tests at the end. I merged both locally. With the merged binary and merged tests,test_replays_after_deadline_are_counted, #620'stest_retries_left_at_end_of_test_time_are_countedandtest_replays_wait_for_auth_after_reconnecteach passed 2/2. Merge order: #613, then #620, then #600. #620 and #600 will each need a trivial rebase of the test file.Tests
There are four new tests. Two are in
tests/test_retry_on_error.py, both standalone only. Each runs--pipeline=32 -c 2for 6 s and sends 4 waves ofCLIENT KILL TYPE normal:test_replays_wait_for_auth_after_reconnectsetsrequirepassfor the run and asserts that noNOAUTHreply appears.test_replays_wait_for_select_after_reconnectuses--select-db=3and asserts that DB 3 has keys and DB 0 has none.The other two:
test_replays_after_deadline_are_counted(standalone, plain TCP) puts the stalling proxy above in front of the server, with--select-db=3. It asserts that JSON Count equals the last progress line and that Connection Errors == 2.test_replica_replays_wait_for_readonly, intests/test_read_preference_failover.py(OSS cluster with replicas), runs--read-preference=secondary --ratio=0:1 --pipeline=32. It sendsCLIENT KILL TYPE normalwaves on the replicas and asserts that the replicas'errorstat_MOVEDis 0.Results:
--tlsWith all three commits rebased on 013cb85 (which includes #591, #593, #599, #612 and #615), these all pass:
test_retry_on_error.py: 15 passed.test_retry_on_error.py: 6 passed, 9 skipped (standalone-only).--use-slaves)test_read_preference_failover.py: 2 passed, 1 skipped (the existing placeholder).Earlier, with the first two commits on a7b9fc9 (which includes #591), these suites all passed:
test_retry_on_error.py,test_reconnections.py,tests_oss_simple_flow.py,test_json_output_integrity.py.test_retry_on_error.py,test_reconnections.py,test_cluster_redirect_stats.py.test_read_preference_failover.py,test_read_preference_modes.py,test_cluster_failover_retry.py.The first commit alone also passed
test_cluster_transaction.pyon the 3-shard cluster.Manual repro:
-a pw -c 2 --pipeline 32with 40CLIENT KILLs. Master gives 256 NOAUTH in each of 3 runs; this PR gives 0.Affected versions
Introduced by 08cfc24 (#381,
--retry-on-error), so the first affected tag is 2.4.0. Affected: 2.4.0 through 2.4.4, 2.5.0, 2.5.1, 2.5.2 and master. Confirmed by running the repro on 2.4.0, 2.5.2 and master; the versions in between are derived from history. 2.3.x and older have no--retry-on-error.Fixes #527
🤖 Generated with Claude Code
Note
Medium Risk
Changes reconnect/replay ordering and end-of-run stats timing in the hot
fill_pipeline/process_responsepath; behavior is well-covered by new integration tests but affects retry-on-error and test-time accounting.Overview
Fixes #527: with
--retry-on-errorand reconnects, in-flight requests are no longer resent immediately onBEV_EVENT_CONNECTED. Replay draining moves intofill_pipeline(), which sends the connection setup ladder (AUTH, SELECT, HELLO, READONLY, CLUSTER SLOTS) first and only then drains the replay queue—still ahead of new work, including after--test-timehas elapsed.Adds
setup_held_for_transaction()so CLUSTER SLOTS stays deferred while a pinned--transactionMULTI is open (same behavior as before, refactored).Stats at deadline:
process_response()now callsset_end_time()only when the run isfinished()andall_connections_idle(), so late replies from post-deadline reconnect resends are counted once and connection-error totals stay correct.Tests: churn/kill scenarios for AUTH, SELECT, replica READONLY ordering, and a stalling-proxy case for deadline accounting.
Reviewed by Cursor Bugbot for commit 24dfedf. Bugbot is set up for automated code reviews on this repo. Configure here.