Skip to content

Don't retry or replay --transaction requests (#611) - #615

Merged
fcostaoliveira merged 1 commit into
masterfrom
fix/txn-retry-exec-without-multi
Oct 14, 2026
Merged

fcostaoliveira merged 1 commit into
masterfrom
fix/txn-retry-exec-without-multi

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

With --transaction --retry-on-error --reconnect-on-error, every dropped connection starts a retry loop that does not end (#611). The replayed EXEC fails with -ERR EXEC without MULTI, gets retried, and fails again for as long as --max-retries allows, which by default is forever.

  • Standalone, 8 s with CLIENT KILL TYPE normal every 0.5 s: about 12k failing EXECs and rc 0.
  • Cluster: the run never reaches --test-time. It keeps sending about 100k EXEC without MULTI per 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 its MULTI, because the server dropped that with the old socket.
  • client::handle_response() retries every error that is not classified as permanent. A resent EXEC never has a MULTI before it, so the retry fails every time.

#575 already drops held --transaction requests (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 reach client::handle_response() are counted as errors instead of being retried. MOVED/ASK under --transaction never reach enqueue_retry(): they already take the transaction branch straight to finalize_dropped_redirect(). The -READONLY reroute has its own !m_config->transaction check 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-error they are logged to --failed-keys-file as REPLAY,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 --transaction are unchanged. The --help text for both --retry-on-error and --transaction now says that --transaction commands are never retried or replayed.

The transaction-not-replayed branch in cluster_client::hand_off_replay_requests() can't be reached under --transaction anymore, because disconnect() 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:

  • The failed tail EXEC after a reconnect is now a terminal error. It writes a ARBITRARY,"","-ERR EXEC without MULTI",0 row to --failed-keys-file. Master wrote none, because it kept retrying.
  • Master's bogus Execs Misses/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 > 1 the 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 MULTI per killed connection, now counted once as an error and not retried. The cluster version of this is #604 / PR #607. The remaining -MOVED/-EXECABORT in 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 4 with CLIENT KILL TYPE normal on every primary, with --reconnect-on-error and --failed-keys-file.

  1. test_transaction_requests_are_not_retried (--retry-on-error, --pipeline 1, kills every 0.5 s for 5 s) asserts:
    • rc 0
    • memtier's retries is 0
    • the server's total errorstat_ERR is ≤ the number of killed connections
    • there is at least one REPLAY,...,"transaction-not-replayed" row
  2. test_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.
  3. test_transaction_drops_not_logged_without_retry (no --retry-on-error) asserts rc 0 and no REPLAY rows.

Discrimination:

standalone cluster
origin/master e4d14e8 (test 1) 7/7 fail: 15,932–38,018 -ERR for 32–40 killed connections fail: runs past --test-time, killed at the timeout
this PR, tests 1–3 11/11 pass 11/11 pass

On this PR, test 1 saw 10–28 -ERR for 20–40 killed connections on standalone, and 11–26 for 48–93 on cluster.

Mutants (one run per env unless noted):

mutant standalone cluster
M1: no --transaction guard in enqueue_retry() or capture_serialized_bytes() (old retry behaviour) killed (tests 1, 2) killed (tests 1, 2; test 1 hit 507k -ERR and the timeout)
M2: disconnect() replays under --transaction again killed (test 1) killed (test 1)
M3: no transaction-not-replayed log killed (test 1) killed (test 1)
M4: dropped requests not uncounted (no dropped++) killed 3/3 (test 2) killed 3/3 (tests 1, 2, 3)
M6: REPLAY rows also logged without --retry-on-error killed (test 3) killed (test 3)
M1a / M1b: only one of the two retry guards removed survives survives

M1a and M1b are equivalent mutants. enqueue_retry() refuses a request with no captured bytes, so either guard alone stops the retries. I kept both: the enqueue_retry() guard states the rule, and the capture skip saves the copy.

Manual repro from #611 with this PR:

  • Standalone: errorstat_ERR 39, retries 0.
  • Cluster: finishes on time with retries 0.

PR #607's branch does not fix this: run against the cluster repro, it also ran past --test-time with 2.4M retries.

Other checks on this branch:

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 duplicate import 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 --transaction from f7f8983 (#390). Both are first in 2.4.0.

  • Confirmed by running the standalone repro: master e4d14e8 (12,345 -ERR), 2.5.2 (1,291), 2.4.0 (4,559). All three exit with rc 0.
  • Derived from history: 2.4.1–2.4.4 and 2.5.0–2.5.1.

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-error are combined (#611): after a disconnect, replayed commands ran without their MULTI, so EXEC failed with EXEC without MULTI and was retried forever (cluster runs could hang past --test-time).

shard_connection now 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-file as REPLAY,transaction-not-replayed. enqueue_retry() and capture_serialized_bytes() bail out when --transaction is set so errors are terminal instead of retried.

Help text documents that --transaction commands 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 --requests stall.

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

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🤖 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 --transaction. The tests are what I'd want for a fix like this: test 1 fails on master on both topologies, and the mutant table shows each piece of the fix is actually covered.

A few small things:

  • Just checking: the --transaction entry in memtier_benchmark.1 mirrors usage(), but the new "not retried or replayed" note was only added to usage(). The man page entry has drifted already. It still says the flag is a no-op in standalone, which usage() no longer says, and that's now less true still, since --transaction turns off retries and replays in standalone too. The comment near memtier_benchmark.cpp:2478 ("in standalone it is a no-op") has the same problem. Maybe worth updating both while you're here, or in a follow-up. --retry-on-error isn't in the man page at all, but that gap predates this PR.
  • I'm fine with keeping both guards (enqueue_retry() and capture_serialized_bytes()) even though either one alone stops the retries; the comments explain why each is there. I think the transaction-not-replayed branch in hand_off_replay_requests() being kept as a guard is also reasonable.
  • Nitpicking: the test file now has three blank lines before _run_transaction_with_kills where the rest of the file uses two. If make format-check doesn't cover Python, it's worth fixing on the final rebase.

One behavioral note, just to confirm it's intended: with --transaction --retry-on-error, --max-retries now has no effect, and no transient error (e.g. -LOADING) is retried either, not only the disconnect case. I think that's right, since a lone retried EXEC or MULTI can never succeed. It might still be worth one line in the --max-retries help text so nobody tunes it and wonders why nothing changes.

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)

@fcostaoliveira
fcostaoliveira force-pushed the fix/txn-retry-exec-without-multi branch from 4a22c22 to c66c659 Compare October 14, 2026 03:56
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. Taking both points:

  • -READONLY reroute calling enqueue_retry() without a --transaction check. I don't think it can fire today. --transaction requires --read-preference primary, which is checked at startup, so no replica connection or READONLY setup is ever made. An OSS cluster replica also answers a write with -MOVED, not -READONLY. Still, I moved the guard into shard_connection::enqueue_retry(): it now returns false under --transaction. That covers every retry path, including client::handle_response(), the -READONLY reroute and the MOVED/ASK retry. On any of them the request is finalized as a terminal error, so m_retry_queue stays empty under --transaction and the else branch in disconnect() has nothing left to drain. capture_serialized_bytes() also skips the copy under --transaction, since nothing resends those bytes anymore.
  • m_config->retry_on_error in the else branch. Agreed. It now checks m_config->retry_on_error && m_config->transaction, so the transaction-not-replayed label is plainly right there. Without --retry-on-error the dropped requests were never going to be resent, so they aren't logged. A new test covers that.

The disconnect half now has tests of its own:

  • test_transaction_requests_are_not_retried also asserts REPLAY,...,"transaction-not-replayed" rows in --failed-keys-file.
  • test_dropped_transaction_requests_do_not_stall_requests_run checks the un-counting with --requests.
  • test_transaction_drops_not_logged_without_retry asserts that no REPLAY rows are written without --retry-on-error.

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]>
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.

--transaction with --retry-on-error: EXEC replayed without its MULTI after a reconnect is retried forever

1 participant