Repository navigation
Resend held retries when a slot map refresh retires a connection - #575
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the hand-off path and the deferred resend in
The core fix looks solid to me. These are mostly questions, and nothing here should block the merge on its own. |
|
Two follow-ups found during this work, split out as separate issues and not addressed in this PR:
|
With --retry-on-error, a connection that drops keeps its in-flight and retry-queued requests in its replay queue, still counted as generated, and resends them once it reconnects. When a CLUSTER SLOTS refresh then finds that the connection owns no slots (for example after its primary died and a replica was promoted), handle_cluster_slots retires it and it never reconnects. Those requests were never completed or uncounted, so a --requests run ended a few requests short and exited 1. When retiring a connection, hand each held request to the connection that now owns its slot's primary. It is resent right away if that connection is up, or once it connects. A request with no key or no slot owner is logged to --failed-keys-file and uncounted, as drain_replay_queue_after_reconnect does for requests it drops. Add an RLTest regression test that kills a primary mid-run in a cluster with replicas, and a CI cell that runs it. Fixes #568 Co-Authored-By: Claude Opus 5.5 <[email protected]>
hand_off_replay_requests() runs inside a CLUSTER SLOTS reply handler, possibly the one of the connection that now owns the slot. Resending from there pushed onto that connection's pipeline mid-process_response(), before its m_cluster_slots was setup_done. adopt_replay_request() now only queues the request and calls schedule_fill(); fill_pipeline() resends it once the connection is connected and set up. A connection that isn't connected yet still resends it when it connects. Drop and uncount, with a --failed-keys-file line, a request that: - is held under --transaction, as MOVED/ASK do, since resending it on another connection would split its MULTI/EXEC block or land inside one that connection has open; - targets a primary that is disconnected with no reconnect pending. The refresh dials every primary without a pending timer, and since #574 a failed dial schedules one, so this is a primary that attempt_reconnect() gave up on (no --reconnect-on-error, or --max-reconnect-attempts reached). adopt_replay_request() asserts the replay queue exists instead of silently dropping the request. Co-Authored-By: Claude Opus 5.5 <[email protected]>
18f8cc8 to
b8c16ff
Compare
|
Thanks for the review. I rebased on master (4146bb8, which includes #574 and #576) and added b8c16ff on top of 0a2e014, which is the original commit after the rebase. 1. Re-entrancy. The old code was safe. 2. Target that never reconnects. The guarantee is weaker than "always connected or connecting", so b8c16ff handles the gap. Every primary in a topology that was just committed is connected, connecting, or waiting on a reconnect timer:
A primary can still end up disconnected with no timer, when 3. Tested with a kill of a primary during
At 4. Nit. Done. 5. Flake risk. Agreed, I'll watch the new CI cell over the next few runs. The test checks Evidence on b8c16ff (local, Redis 8.6.0):
I updated the PR description to match. 🤖 Generated with Claude Code |
…s it When every slot moves off a primary mid-run, that primary's connection answers -MOVED, sends CLUSTER SLOTS itself and, handling the reply in its own process_response(), handle_cluster_slots() retires it: disconnect() frees the bufferevent and empties the pipeline. The loop then went on parsing replies still buffered behind the CLUSTER SLOTS reply and popped an empty pipeline. With --retry-on-error (whose resends follow the CLUSTER SLOTS request on that connection) this aborted with "Assertion m_pending_resp >= 0" in pop_req(); release builds use a garbage request. process_response() now notes a per-connection disconnect counter before parsing and stops once a handler has torn the connection down. disconnect() has already requeued (--retry-on-error, handed off by #575) or uncounted every request those replies answered. Without --retry-on-error the same retirement ended runs with "client(s) stopped before reaching their stop condition": producers parked by hold_pipeline() waited on in-flight work of the retired connection, which disconnect() dropped without waking anyone, so the event loop ran out of events. handle_cluster_slots() now wakes every live connection whenever it retires a connection (dropping its staged commands, key pool, pipeline or unplaceable replays), as it already did for --multi-key-get. tests/test_cluster_failover_retry.py moves every slot of a primary to another primary (and back) six times during a --requests run, with and without --retry-on-error, and checks the exact op count. On master the first test aborts and the second stops early in every run; both pass with this change. Fixes #578 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s it When every slot moves off a primary mid-run, that primary's connection answers -MOVED, sends CLUSTER SLOTS itself and, handling the reply in its own process_response(), handle_cluster_slots() retires it: disconnect() frees the bufferevent and empties the pipeline. The loop then went on parsing replies still buffered behind the CLUSTER SLOTS reply and popped an empty pipeline. With --retry-on-error (whose resends follow the CLUSTER SLOTS request on that connection) this aborted with "Assertion m_pending_resp >= 0" in pop_req(); release builds use a garbage request. process_response() now notes a per-connection disconnect counter before parsing and stops once a handler has torn the connection down. disconnect() has already requeued (--retry-on-error, handed off by #575) or uncounted every request those replies answered. Without --retry-on-error the same retirement ended runs with "client(s) stopped before reaching their stop condition": producers parked by hold_pipeline() waited on in-flight work of the retired connection, which disconnect() dropped without waking anyone, so the event loop ran out of events. handle_cluster_slots() now wakes every live connection whenever it retires a connection (dropping its staged commands, key pool, pipeline or unplaceable replays), as it already did for --multi-key-get. tests/test_cluster_failover_retry.py moves every slot of a primary to another primary (and back) six times during a --requests run, with and without --retry-on-error, and checks the exact op count. On master the first test aborts and the second stops early in every run; both pass with this change. Fixes #578 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With --transaction --retry-on-error --reconnect-on-error, a dropped connection's in-flight requests were replayed after the reconnect without their MULTI, which the server dropped with the old socket. The replayed EXEC failed with "-ERR EXEC without MULTI", and that error was retried: the same EXEC was resent and failed again, without end under the default --max-retries=-1. Standalone runs sent thousands of failing EXECs per second and still exited 0; cluster runs never reached --test-time. Resending one command of a MULTI block on its own can't work, so under --transaction: - enqueue_retry() refuses every request, so error replies are counted as errors on every path (client::handle_response, the -READONLY reroute) instead of being retried. The replay bytes are no longer copied, since nothing resends them. - disconnect() drops in-flight requests instead of queueing them for replay. They are uncounted as without --retry-on-error and logged to --failed-keys-file as transaction-not-replayed, as the slot map hand-off already does for retired connections (#575). Retries without --transaction are unchanged. Fixes #611 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With --transaction --retry-on-error --reconnect-on-error, a dropped connection's in-flight requests were replayed after the reconnect without their MULTI, which the server dropped with the old socket. The replayed EXEC failed with "-ERR EXEC without MULTI", and that error was retried: the same EXEC was resent and failed again, without end under the default --max-retries=-1. Standalone runs sent thousands of failing EXECs per second and still exited 0; cluster runs never reached --test-time. Resending one command of a MULTI block on its own can't work, so under --transaction: - enqueue_retry() refuses every request, so error replies from client::handle_response() are counted as errors instead of being retried. The replay bytes are no longer copied, since nothing resends them. - disconnect() drops in-flight requests instead of queueing them for replay. They are uncounted as without --retry-on-error and logged to --failed-keys-file as transaction-not-replayed, as the slot map hand-off already does for retired connections (#575). That hand-off branch is now only a guard. Retries without --transaction are unchanged. Fixes #611 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With --transaction --retry-on-error --reconnect-on-error, a dropped connection's in-flight requests were replayed after the reconnect without their MULTI, which the server dropped with the old socket. The replayed EXEC failed with "-ERR EXEC without MULTI", and that error was retried: the same EXEC was resent and failed again, without end under the default --max-retries=-1. Standalone runs sent thousands of failing EXECs per second and still exited 0; cluster runs never reached --test-time. Resending one command of a MULTI block on its own can't work, so under --transaction: - enqueue_retry() refuses every request, so error replies from client::handle_response() are counted as errors instead of being retried. The replay bytes are no longer copied, since nothing resends them. - disconnect() drops in-flight requests instead of queueing them for replay. They are uncounted as without --retry-on-error and logged to --failed-keys-file as transaction-not-replayed, as the slot map hand-off already does for retired connections (#575). That hand-off branch is now only a guard. Retries without --transaction are unchanged. Fixes #611 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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-retry", count it as an error like a refused retry, uncount it with dec_reqs_generated(), and print one warning. 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]>
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 like a refused retry, uncount it with dec_reqs_generated(), and print one warning. 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]>
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]>
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]>
Problem
In cluster mode with
--retry-on-error(and--reconnect-on-error), a--requests=Nrun stops short once a CLUSTER SLOTS refresh retires a connection. For example,kill -9a primary mid-run so that its replica gets promoted. The thread stops at N minus up to--pipelinerequests per affected connection, prints "ended before the requested request count was reached", and the run exits 1.Root cause
When a connection drops,
disconnect()moves its in-flight requests, plus anything in its retry queue, intom_replay_queue. They stay counted as generated so they can be resent after a reconnect. After the replica is promoted, the refresh incluster_client::handle_cluster_slotsfinds that the old connection owns no slots and retires it. The retirement loop compensates staged monitor commands and key pools, but not these queues. The connection never reconnects, sodrain_replay_queue_after_reconnect()(and itsdec_reqs_generated, added in #559) never runs. Those requests are never completed and never uncounted, soreqs_generatedstays ahead of what can ever be processed.Fix
When the retirement loop retires a connection,
hand_off_replay_requests()moves every request it still holds for resend (replay queue, then retry queue) to the connection that owns the request's slot primary in the new topology.adopt_replay_request()only queues it in that connection's replay queue and callsschedule_fill(). Nothing is written from inside the CLUSTER SLOTS reply handler, which may belong to the adopting connection itself.fill_pipeline()resends the request through the existingdrain_replay_queue_after_reconnect()path, so--max-retries, the missing-bytes checks and thedec_reqs_generatedon drop all still apply.--failed-keys-fileasREPLAYand uncounted withdec_reqs_generated, the same as a drop indrain_replay_queue_after_reconnect():no-slot-owner-for-replay: the request has no key or its slot has no owner.slot-owner-down-for-replay: the slot owner is disconnected with no reconnect pending, soattempt_reconnect()gave up on it (no--reconnect-on-error, or--max-reconnect-attemptsreached). The refresh dials every primary without a pending timer, and since Retry cluster shard connections that fail to dial synchronously #574 a failed dial schedules one, so this is the only way a just-committed primary ends up there.transaction-not-replayed: any request held under--transaction. This matches MOVED/ASK under--transaction. Resending it on another connection would split its MULTI/EXEC block, or land it inside a MULTI that the target has open (Never send CLUSTER SLOTS inside an open --transaction MULTI (#569) #576).Accounting stays consistent with #557/#559/#560:
Tests
New RLTest test
tests/test_cluster_failover_retry.py, with a new CI cell "OSS-CLUSTER + replicas: primary failover with retries". It needs replicas that take part in failover, so it skips in the other cells. The test:cluster-node-timeoutto 2 s at runtime.-t1 -c2 -n 500000 --pipeline 16 --retry-on-error --reconnect-on-error.SIGKILLs a non-seed primary once it is serving traffic.RLTest prints a "process is not alive" warning at teardown for the killed primary. That warning is expected and doesn't fail the test.
The test checks
>=rather than==because requests retried after MOVED/ASK are counted twice in ops (#579).Before/after on a local cluster (Redis 8.6.0, 3 primaries + 1 replica of the killed primary,
--cluster-node-timeout 2000). The first two rows are from the first revision, against 667f187. The rest are from the head of this branch, rebased on 4146bb8:-t1 -c2 -n 2000000 --pipeline=16 --retry-on-error --reconnect-on-error,kill -9of a primary after 3 s--transaction --pipeline=1(--command "SET __key__ __data__" --command "GET __key__",-n 400000)transaction-not-replayedper runRegression runs at head:
test_retry_on_error.py,test_reconnections.py,test_cluster_failover_retry.pyandtest_cluster_transaction.pypass on OSS cluster (35/35) and standalone (35/35).test_read_preference_failover.pyandtest_read_preference_modes.pypass with replicas (8/8).Not addressed here
pop_req(): Assertion 'm_pending_resp >= 0', on master and on this branch. The connection that receives the CLUSTER SLOTS reply retires itself inside its ownprocess_response(). Akill -9failover doesn't hit it, because the dead connection can't ask for the refresh.--transaction --pipeline > 1, the same kill crashes the worker withvector::_M_range_check, on master and on this branch, before the replica is promoted. So the hand-off is never reached there.Fixes #568
Affected versions: 2.4.0–2.5.2 and master (introduced by 08cfc24 / #381; widened by #559)
🤖 Generated with Claude Code