Repository navigation
Don't retry or replay --transaction requests (#611) - #615
Conversation
|
🤖 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, and I agree with the approach. Resending part of a MULTI block can't work, and dropping the in-flight requests is consistent with what #575 and the MOVED/ASK path already do under A few small things:
One behavioral note, just to confirm it's intended: with Overall the fix looks solid to me. The doc points are the only things I'd want looked at before this merges. (would file this as a comment, not a formal block) |
4a22c22 to
c66c659
Compare
|
Thanks. Taking both points:
The disconnect half now has tests of its own:
The mutant results are in the PR body. 🤖 Generated with Claude Code |
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]>
c66c659 to
3117f60
Compare
Problem
With
--transaction --retry-on-error --reconnect-on-error, every dropped connection starts a retry loop that does not end (#611). The replayedEXECfails with-ERR EXEC without MULTI, gets retried, and fails again for as long as--max-retriesallows, which by default is forever.CLIENT KILL TYPE normalevery 0.5 s: about 12k failingEXECs and rc 0.--test-time. It keeps sending about 100kEXEC without MULTIper second until it is killed.Root cause
shard_connection::disconnect()queues every in-flight workload request for replay. After the reconnect the tail of an interrupted block is resent without itsMULTI, because the server dropped that with the old socket.client::handle_response()retries every error that is not classified as permanent. A resentEXECnever has aMULTIbefore it, so the retry fails every time.#575 already drops held
--transactionrequests (transaction-not-replayed), but only when a slot map refresh retires a connection, not on a reconnect of the same connection.Fix
Resending one command of a MULTI block on its own can't work, so under
--transaction:shard_connection::enqueue_retry()refuses every request, so error replies that reachclient::handle_response()are counted as errors instead of being retried. MOVED/ASK under--transactionnever reachenqueue_retry(): they already take the transaction branch straight tofinalize_dropped_redirect(). The-READONLYreroute has its own!m_config->transactioncheck since Record the key of --command requests in --failed-keys-file #599.capture_serialized_bytes()skips the replay copy on the send path, since nothing resends those bytes.disconnect()drops in-flight requests instead of queueing them for replay. They are uncounted the same way as without--retry-on-error. With--retry-on-errorthey are logged to--failed-keys-fileasREPLAY,transaction-not-replayed, like Resend held retries when a slot map refresh retires a connection #575. Without it they were never going to be resent, so they are not logged.Retries without
--transactionare unchanged. The--helptext for both--retry-on-errorand--transactionnow says that--transactioncommands are never retried or replayed.The
transaction-not-replayedbranch incluster_client::hand_off_replay_requests()can't be reached under--transactionanymore, becausedisconnect()no longer queues those requests. I kept it as a guard, with a one-line comment saying so.Visible output changes under
--transaction --retry-on-error:EXECafter a reconnect is now a terminal error. It writes aARBITRARY,"","-ERR EXEC without MULTI",0row to--failed-keys-file. Master wrote none, because it kept retrying.ExecsMisses/sec and Aborts/sec are gone (892/s each on the 8 s standalone repro). They came from the endlessly retried error replies. With this PR both read 0.00.I chose dropping over replaying the whole block from its
MULTI. At--pipeline > 1the in-flight requests can start and end in the middle of blocks. Dropping also matches what #575 and the MOVED/ASK paths already do under--transaction.After a reconnect, the rotation still sends the not-yet-sent rest of the interrupted block. On standalone that gives at most one
EXEC without MULTIper killed connection, now counted once as an error and not retried. The cluster version of this is #604 / PR #607. The remaining-MOVED/-EXECABORTin cluster runs are #603 / PR #606.Test evidence
New tests in
test_retry_on_error.py, which run on standalone and on a 3-primary cluster. Each runs MULTI/SET/EXEC at-t 2 -c 4withCLIENT KILL TYPE normalon every primary, with--reconnect-on-errorand--failed-keys-file.test_transaction_requests_are_not_retried(--retry-on-error,--pipeline 1, kills every 0.5 s for 5 s) asserts:retriesis 0errorstat_ERRis ≤ the number of killed connectionsREPLAY,...,"transaction-not-replayed"rowtest_dropped_transaction_requests_do_not_stall_requests_run(--retry-on-error,--pipeline 4,--requests 30000, kills every 0.3 s) asserts rc 0 and no "stopped before reaching" in stderr.test_transaction_drops_not_logged_without_retry(no--retry-on-error) asserts rc 0 and no REPLAY rows.Discrimination:
-ERRfor 32–40 killed connections--test-time, killed at the timeoutOn this PR, test 1 saw 10–28
-ERRfor 20–40 killed connections on standalone, and 11–26 for 48–93 on cluster.Mutants (one run per env unless noted):
--transactionguard inenqueue_retry()orcapture_serialized_bytes()(old retry behaviour)-ERRand the timeout)disconnect()replays under--transactionagaintransaction-not-replayedlogdropped++)--retry-on-errorM1a and M1b are equivalent mutants.
enqueue_retry()refuses a request with no captured bytes, so either guard alone stops the retries. I kept both: theenqueue_retry()guard states the rule, and the capture skip saves the copy.Manual repro from #611 with this PR:
errorstat_ERR39,retries 0.retries 0.PR #607's branch does not fix this: run against the cluster repro, it also ran past
--test-timewith 2.4M retries.Other checks on this branch:
test_retry_on_error.py, rebased on 4d97c8b (Record the key of --command requests in --failed-keys-file #599): 12/12 on standalone and 12/12 on cluster.test_transaction_pipeline.py: 3/3 on standalone and 3/3 on cluster.test_cluster_transaction.py: 17/17.Merge order
#615 merges before #613 and #620. All three append tests to the end of
tests/test_retry_on_error.py, so the later two need a trivial union of the appended blocks. Watch for a duplicateimport re.Affected versions
2.4.0 through 2.5.2 (latest) and master. The replay queue and the retry of any non-permanent error come from 08cfc24 (#381), and
--transactionfrom f7f8983 (#390). Both are first in 2.4.0.-ERR), 2.5.2 (1,291), 2.4.0 (4,559). All three exit with rc 0.Fixes #611
Found during the review of #591. Related: #575, #603 / #606, #604 / #607.
🤖 Generated with Claude Code
Note
Medium Risk
Changes reconnect and error-retry behavior for transaction workloads when --retry-on-error is enabled; non-transaction retry paths are unchanged but the interaction with disconnect accounting is subtle.
Overview
Fixes an infinite retry loop when
--transaction,--retry-on-error, and--reconnect-on-errorare combined (#611): after a disconnect, replayed commands ran without theirMULTI, soEXECfailed with EXEC without MULTI and was retried forever (cluster runs could hang past--test-time).shard_connectionnow treats transaction workloads as non-retryable:disconnect()does not move in-flight work to the replay queue; drops are uncounted and, with--retry-on-error, logged to--failed-keys-fileasREPLAY,transaction-not-replayed.enqueue_retry()andcapture_serialized_bytes()bail out when--transactionis set so errors are terminal instead of retried.Help text documents that
--transactioncommands are never retried or replayed.cluster_client::hand_off_replay_requests()keeps its transaction guard with an updated comment (defensive only after the disconnect change). New integration tests kill connections during MULTI/SET/EXEC rotations to assert zero retries, bounded server errors, and no--requestsstall.Reviewed by Cursor Bugbot for commit 3117f60. Bugbot is set up for automated code reviews on this repo. Configure here.