Skip to content

Don't continue a standalone --transaction block after a reconnect drops its MULTI - #634

Merged
fcostaoliveira merged 4 commits into
masterfrom
fix/standalone-txn-reconnect
Oct 16, 2026
Merged

fcostaoliveira merged 4 commits into
masterfrom
fix/standalone-txn-reconnect

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

With --transaction against a single endpoint plus --reconnect-on-error, a connection killed after it sent a rotation's MULTI reconnects with the rotation index still on the next command of the block. The rest of the block then goes out on the new socket: the SET runs outside any transaction, the EXEC fails with -ERR EXEC without MULTI, and the run still exits 0. Details are in #633.

Root cause

client::create_request() is the standalone path. It sends m_executed_command_index without checking that the block's MULTI is still open. shard_connection already tracks this (m_multi_open, set in send_arbitrary_command_end() and cleared on connect/disconnect), but nothing on the standalone path reads it.

cluster_client overrides create_request(), but it can still fall through to client::create_request() when its key pool is empty. On that path the rotation's MULTI may sit on a different connection than conn_id, so the new check is guarded with !m_config->cluster_mode. Cluster mode keeps its own check in cluster_client::create_arbitrary_request() (#607).

Fix

The same rule #607 added for cluster mode, applied to the standalone path:

  • A new client::m_txn_multi_sent is set when the rotation's MULTI is sent and cleared when EXEC/DISCARD is sent.
  • In client::create_request(), outside cluster mode, if it is set, the current command is not the opener, and the connection no longer has is_multi_open(), the command is skipped. Skipping continues up to and including the EXEC/DISCARD, and the rotation advances without sending anything. The next rotation starts with a fresh MULTI. Commands after the EXEC (outside the block) are sent as normal.
  • Skipped commands are never sent, so they are not counted in m_reqs_generated. --requests runs still end on processed replies, the same as for requests dropped on a disconnect.

The code change is only in client.cpp/client.h, plus the standalone test.

Docs: the man page's --transaction entry said that standalone mode needs no pinning, and the code comment called the flag a standalone no-op. Both were out of date. The entry is now regenerated from usage() (help2man output, that entry only). That also brings in the same-key/CROSSSLOT paragraph --help already had. The entry and --help used to say that an interrupted rotation's stats "will be inaccurate". They now say that after a reconnect inside a MULTI block, the rest of that block, through EXEC/DISCARD, is skipped and not counted, so per-command counts no longer follow the command ratio. They also say that replies already received for that block stay counted.

Test evidence

New test: test_retry_on_error.py::test_transaction_lost_multi_is_not_continued (skipped on cluster, since #607 covers cluster mode). The rotation is MULTI, 50x SET, EXEC, 50x GET, at -t 2 -c 4 --pipeline 7, for 6s with CLIENT KILL TYPE normal every 0.3s. Long blocks make most kills land inside a block, and a pipeline of 7 does not divide the rotation, so kills don't always land on a block boundary. The test asserts:

  • exit 0, no EXEC without MULTI in stderr, and zero errorstat_ERR;
  • the GETs after the EXEC are still sent: 50 * MULTI calls - GET calls is at most 50 * 8 (partial rotations of the 8 connections at the end) plus 7 * killed connections (GETs in flight on a killed connection). This catches a skip that doesn't stop at the EXEC: the mutant that never clears m_txn_multi_sent in the skip path also drops the following GETs.

Local runs, RLTest --env oss, standalone redis (bound = 680 with 40 kills per run):

binary runs result -ERR replies missing GETs
master 0298524 4 4/4 FAIL (EXEC without MULTI) 15, 17, 19, 22 143-332
this PR 8 8/8 PASS 0 in every run 125-409
mutant: skip never clears m_txn_multi_sent 5 5/5 FAIL (GET bound) 0 1108-1584

Same repro outside RLTest, from the first version of this PR: master gives 23 EXEC without MULTI with exit 0; this PR gives 0. commandstats shows SET == EXEC with the fix.

The whole test_retry_on_error.py passes with the fix under --env oss (18/18). After rebasing onto fd7b23c, the new test and test_transaction_requests_are_not_retried pass again. I also ran test_transaction_pipeline.py (3/3 pass).

Fixes #633

Refs #673: this removes the EXEC without MULTI part of the --reconnect-interval variant (repro there: 572 errors → 0). Keeping the reconnect on a block boundary and the QUEUED accounting are still open.

Affected versions

2.4.0 through 2.5.2 and master. This came in with --transaction itself (f7f8983, #390). I confirmed it by running master 38fae5d, 2.5.2 and 2.4.0, and the new test fails on master 0298524.

🤖 Generated with Claude Code

@fcostaoliveira
fcostaoliveira force-pushed the fix/standalone-txn-reconnect branch from 7539e2f to a3037ed Compare October 15, 2026 06:28
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🤖 Automated first-pass review — a human maintainer's review is still required before merge.

Thanks, this reads well. It's the same rule #607 added in cluster_client::create_arbitrary_request(), applied to the standalone path, and leaving cluster mode out (because of the empty-key-pool fallthrough) seems right to me.

Things I checked that hold up:

  • A skipped command doesn't add to m_pipeline. That means the fill_pipeline() loop keeps calling create_request(), and the skip runs through to the EXEC and then the next MULTI in one pass. So skipping can't stall the connection.
  • If create_arbitrary_request() returns false on the EXEC, m_txn_multi_sent stays set and the EXEC is tried again on the next call. I think that's correct.
  • _run_transaction_with_kills() already runs CONFIG RESETSTAT, so the cmdstat_multi/cmdstat_get numbers in the new test don't include traffic from earlier tests in the file.
  • The test fails on master, and the mutant that never clears m_txn_multi_sent fails the GET bound. That's the regression-test standard we want, like tests/test_json_output_integrity.py in Fix JSON Totals latency precision and add integrity regression tests #364.

One question, not a blocker: the only signal that a block was skipped is benchmark_debug_log. Users will now see per-command counts that don't follow --command-ratio after kills, and the docs explain why, but nothing in the run output says it happened. Did you consider a one-time stderr note when the first skip happens? It's fine to leave that for a follow-up with #673.

Nitpicking: the man page change also rewrites the same-key/CROSSSLOT paragraph. I guess that's just help2man catching up with --help, but it's more than #633 needs. It might be worth one line in the PR description so nobody reading the diff later is surprised.

The fix looks solid to me as it stands.

@fcostaoliveira
fcostaoliveira force-pushed the fix/standalone-txn-reconnect branch from a3037ed to 49bd158 Compare October 15, 2026 07:06
fcostaoliveira added a commit that referenced this pull request Oct 15, 2026
…imit

The standalone "Run tests" cells run the whole RLTest suite serially.
After the tests added on 2026-10-13/14 the three TLS cells take
1300-1500 s against a 25-minute (1500 s) step limit, so a slow runner
cancels the job even when every test passed (PR #634, run 38692596851).
Plaintext (~1270 s) and coverage (~1257 s) are close behind.

Set PARALLELISM=2 on the four standalone cells, as the cluster cells
already do; run_tests.sh passes it to RLTest --parallelism, which gives
each worker its own redis env on a distinct port range. Raise the
test-ubuntu and coverage step limits to 40 minutes for headroom. The
coverage job stays serial.

Fixes #679

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 16, 2026
…imit

The standalone "Run tests" cells run the whole RLTest suite serially.
After the tests added on 2026-10-13/14 the three TLS cells take
1300-1500 s against a 25-minute (1500 s) step limit, so a slow runner
cancels the job even when every test passed (PR #634, run 38692596851).
Plaintext (~1270 s) and coverage (~1257 s) are close behind.

Set PARALLELISM=2 on the four standalone cells, as the cluster cells
already do; run_tests.sh passes it to RLTest --parallelism, which gives
each worker its own redis env on a distinct port range. Raise the
test-ubuntu and coverage step limits to 40 minutes for headroom. The
coverage job stays serial.

Fixes #679

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira and others added 4 commits October 16, 2026 08:42
…ps its MULTI

With --transaction against a single endpoint, a connection killed after
it sent a rotation's MULTI reconnects with the rotation index still on
the next command of the block. The rest of the block (SET, EXEC) then
went out on the new socket: the SET ran outside any transaction and the
EXEC failed with "EXEC without MULTI", while the run still exited 0.

client::create_request() (the standalone path) now remembers that this
rotation's MULTI was sent. If the connection no longer has the MULTI
open, it skips the rest of the block up to and including the
EXEC/DISCARD, without sending or counting it. The server already
discarded what was queued. This is the same rule #607 adds for cluster
mode in cluster_client::create_arbitrary_request().

Fixes #633

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… EXEC

Cluster mode falls through to client::create_request() when its key
pool is empty, and there the rotation's MULTI may sit on another
connection than conn_id, so is_multi_open() on conn_id says nothing
about it. Cluster mode keeps its own check in
cluster_client::create_arbitrary_request().

Extend test_transaction_lost_multi_is_not_continued with 50 GETs after
the EXEC and check the server's GET count against the MULTI count, so a
skip that does not end at the EXEC (m_txn_multi_sent left set) fails it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The man page still called --transaction a no-op in standalone mode, and
both it and --help only said the interrupted rotation's stats would be
inaccurate. Say what happens now: after a reconnect inside a MULTI
block, the rest of that block, through EXEC/DISCARD, is skipped and not
counted, so per-command counts no longer follow the command ratio.

Name the thread/client counts of _run_transaction_with_kills() so the
GET bound in test_transaction_lost_multi_is_not_continued follows them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The man page still said standalone needs no pinning and described the
old cluster-only wording; regenerate its --transaction entry from
usage() (help2man output, entry only). Say that replies already received
for a block cut short by a reconnect stay counted, and drop the code
comment that called --transaction a standalone no-op.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/standalone-txn-reconnect branch from 49bd158 to 5d08ca2 Compare October 16, 2026 07:42
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Re the first-pass review's nit: the code comment near the --transaction check that called the option a standalone no-op is fixed in 5d08ca2. That commit is rebased on master cf5753f. It now says that in standalone mode --transaction keeps every __key__ of a rotation on the same key and skips the rest of a MULTI block after a reconnect.

The same commit regenerates the man page's --transaction entry from usage(), using the help2man output for that entry only, so it matches --help. The old entry still described cluster-only pinning. It also says that replies already received for a block cut short by a reconnect stay counted.

The earlier red check was the 25-minute step timeout (#679), which #683 has now fixed.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

On the updated review:

@fcostaoliveira
fcostaoliveira merged commit c4656f4 into master Oct 16, 2026
129 checks passed
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.

Standalone --transaction: rest of a MULTI block is sent after a reconnect drops its MULTI (EXEC without MULTI)

1 participant