Skip to content

Finish transaction rotations before planned reconnects - #807

Merged
fcostaoliveira merged 3 commits into
masterfrom
codex/fix673-safe-transaction-reconnect-20261023
Oct 23, 2026
Merged

fcostaoliveira merged 3 commits into
masterfrom
codex/fix673-safe-transaction-reconnect-20261023

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Planned --reconnect-interval reconnects can discard acknowledged writes inside MULTI. On current master, 27 requests with MULTI/SET/EXEC and interval 8 report 10 SET replies while Redis executes only 7, at pipelines 1 and 8. The last rotation completes, so those missing writes come from earlier planned disconnects, independently of the request-budget tail in #647.

Root cause

The planned reconnect interval can fall inside a transaction command rotation, closing the connection after QUEUED acknowledgements but before EXEC.

Fix

With --transaction, finish the current weighted command rotation, drain its replies, then reconnect. Measure the next interval from that actual boundary: MULTI/SET/EXEC with interval 8 reconnects after 9 commands. Generation and reconnect scheduling share the same boundary check, including WATCH prefixes and command ratios. A second check after generation handles the lost-MULTI skip reaching a boundary without another response callback. Nontransaction interval behavior and the #634 unplanned-loss protection remain unchanged.

Counts/latencies still describe replies: a SET inside MULTI records its QUEUED acknowledgement. This does not reinterpret historical samples as executed-command statistics. README/help/manpage explain that unplanned loss, DISCARD or aborted EXEC can retain acknowledgements for unexecuted work, and that request/time limits still apply normally. Together with the merged #634 unplanned-loss protection, this resolves #673 using its explicitly offered compatibility option: document acknowledgement-based accounting and prevent planned reconnects from cutting a transaction. The separate request-budget tail remains tracked in #647.

Tests

  • Six real Redis/proxy baseline/fixed pairs with private authentication. Interval 8 now reports and executes 9 SETs; the original 3000-request interval-7 case now executes all 1000 SETs, with no unprotected SET or EXEC error.
  • Twenty bounded synthetic process configurations check full wire rotations, committed versus discarded commands, intervals cutting after MULTI/QUEUED and inside WATCH prefixes, weighted commands, pipelines 1/8/16, and intentional unplanned loss. The committed regression fails against the baseline.
  • All 17 unit programs, C++ format check, Black, Ruff F and diff check pass. A fresh ASan/LSan build passes all 20 focused configurations; actual RLTest passes 8/8, including existing nontransaction killed-inflight/reconnect coverage. Six further real Redis controls cover weighted WATCH execution, preserved DISCARD acknowledgement semantics and the separate request-budget tail. Removing only the post-generation reconnect check makes the interval-1 unplanned-loss case fail after one processed MULTI; final source passes. Independent review and final CI remain pending.

The final integration head 29215fe normally merges master through #814, including the eight-shard coverage capacity fix and #810 bounded stderr logging. Clean build passes all17 unit programs;12 actual RLTest functions pass in46seconds on private authenticated Redis, covering transaction reconnect, connection-kill recovery, logging and weighted latency. All823 discovered tests are assigned exactly once across eight nonempty shards. The transaction implementation and committed regression blobs are unchanged from reviewed 1100e75. New-head CI and seven focused rechecks remain required; the earlier coverage timeout is not waived.

Affected versions

Transaction support first appeared in 2.4.0 (f7f8983, #390). The original issue affects 2.4.0 through 2.5.2; history derives the older tags, while the issue independently tested 2.5.2. #634 fixed continuing a lost block, but its planned-drop residual is reproduced here on master 6818fe3. This PR does not claim fresh executions of every release.

Fixes #673.

🤖 Generated with Claude Code


Note

Medium Risk
Changes when standalone connections reconnect under --transaction and --reconnect-interval, which can affect benchmark fidelity and connection churn; non-transaction interval behavior is intended to stay the same.

Overview
With --transaction, planned --reconnect-interval no longer disconnects mid–command rotation (e.g. after MULTI/QUEUED but before EXEC). The client waits until at least N requests have been generated since the last planned reconnect, then finishes the current weighted --command rotation, drains replies, and reconnects at the next rotation boundary (including WATCH prefixes and command ratios). The next interval is measured from that actual boundary, not a raw request modulus.

hold_pipeline and a new prepare_transaction_reconnect / reconnect_transaction_interval path in shard_connection share the same boundary logic; the old per-response modulus reconnect is skipped when --transaction is set. Unplanned reconnect and lost-MULTI skip behavior is unchanged; stats still count QUEUED acks inside MULTI, not executed commands.

README, --help, and the manpage document transaction rotations vs planned reconnects. A new RLTest module exercises full wire rotations, weighted commands, pipelining, and unplanned loss.

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

@github-actions

github-actions Bot commented Oct 23, 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 fix, the tests and the docs. Finishing the rotation and measuring from that boundary seems like the right compatible option from #673. Non-transaction --reconnect-interval stays exactly as it was. Under --transaction the interval becomes "at least N, rounded up to the next rotation boundary." That is a behavior change, but it's limited to the case that was losing writes, and it's documented in --help, the man page and the README, so I'm fine with it. A few comments:

  1. Base counter vs. due counter. prepare_transaction_reconnect() sets m_txn_reconnect_reqs_base = m_reqs_processed, but transaction_reconnect_due() measures m_reqs_generated - m_txn_reconnect_reqs_base. With a drained pipeline these should usually be equal. After an unplanned loss, though, requests that were generated but never processed would make generated > processed. The next planned interval would then start partly used up, and the reconnect would come early. The m_reqs_generated < m_txn_reconnect_reqs_base guard also suggests the two counters were expected to drift. I may be missing something, but is there a reason not to use m_reqs_generated for the base too? If processed is intentional, could the comment say why?

  2. Two reconnect paths. The planned reconnect now lives in two places: the old modulo path in process_response() for non-transaction runs, and reconnect_transaction_interval() called from fill_pipeline() for transaction runs. Both do the same disconnect/connect/exit(failure_exit_code()) sequence. Could they share one helper, so a later change to reconnect error handling can't update only one of them? A soft suggestion, not a blocker.

  3. fill_pipeline hot path. The check only runs when both --transaction and --reconnect-interval are set, so normal runs pay nothing. Once the interval is reached, transaction_reconnect_due() scans arbitrary_commands on every call to find the first executable entry. That entry never changes during a run, so I guess it could be computed once.

  4. Nitpicking: The new README section reads partly like a changelog ("This change prevents planned reconnects from deliberately discarding that work…", "the separate issue --transaction with --requests: run can end after a MULTI without its EXEC when --requests is not a multiple of the block length #647"). That wording will age badly in user docs once --transaction with --requests: run can end after a MULTI without its EXEC when --requests is not a multiple of the block length #647 is fixed. I'd describe only the current behavior and keep the history in the PR or release notes.

  5. Nitpicking: In the test peer, self.server.errors.append(...) runs without self.server.lock, while every other shared field takes it. It's harmless with CPython's GIL, but it stands out.

The synthetic peer test is a good fit here. It checks the actual commands on the wire and committed vs. discarded writes, not just reported counts. The description says it fails on the pre-fix code, which is the bar we want for a fix like this (PR#364 is an earlier example in this repo).

Also, the description says independent review and the new-head CI are still pending. The core fix looks solid. I'd mainly like an answer on the processed/generated base before this merges.

(Would file this as a comment, not a formal block.)

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

The generated/processed baseline uses the standalone transaction invariant at a drained pipeline: generated work either received a final reply (processed), remains in flight, or was dropped and removed from generated by disconnect(). Transactions do not enter the retry/replay queues, and skipped commands never increment generated. Thus generated and processed are equal at this boundary, including after the unplanned-loss controls; the lower-than-base guard protects the unsigned subtraction rather than documenting an expected drift. Taking the base from generated would be equivalent under this invariant. The next interval starts from the actual drained boundary.

The post-generation check is necessary in the committed interval-1 lost-MULTI case. I built a narrow mutant removing only that check: it exits 1 after one processed MULTI with “client(s) stopped before reaching their stop condition.” The final head passes. The acknowledged MULTI reaches the interval, the dropped SET is uncounted, and skipping EXEC reaches the boundary without creating a request or a future response callback.

The repeated disconnect/connect action preserves the existing nontransaction scheduling path; factoring that short action is reasonable cleanup but is not needed for the counter/boundary behavior. The documentation wording will be checked in the maintainer review; current help/manpage describe the behavior directly.

Validation now includes the 20 process configurations under ASan/LSan, 17 unit programs, 8 actual RLTest tests (including the existing nontransaction reconnect/drop regression), and real Redis/proxy controls. DISCARD deliberately remains 9 SET acknowledgements with zero SET executions; a request budget ending inside a rotation remains the separate tail limitation. Refs #673 leaves the original accounting-contract acceptance explicit; this PR does not claim execution-based statistics or automatic closure of the whole issue.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

bugbot run

Please review current integration head29215fe5d1d15ab13b6b7ecb80b9842e78fae63a. It combines the unchanged transaction reconnect fix with merged weighted latency, WAIT totals, bounded logging and eight-shard coverage changes. Clean17/17 units and12/12 focused runtime functions pass; full CI and independent rechecks remain pending. The automatic check skipped the unchanged PR patch.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Following the 17:43:21 review update:

  1. At a drained standalone transaction boundary, generated and processed are equal. Disconnect uncounts dropped workload requests; lost-MULTI skipping advances the command rotation without generating another request. The independent current-head GDB probe observed equality at all24 planned reconnect boundaries, including the natural lost-block timer case (1/1/1, then4/4/4 through25/25/25 for generated/processed/new baseline). Using processed keeps the same completed-work basis as the existing non-transaction interval; the less-than guard is defensive unsigned-underflow protection, not a known normal counter divergence. No interval shift occurred.

  2. The rate-timer path is reachable naturally. With transaction, interval1, pipeline1, rate20 and a dropped queued SET, skipping the lost block reaches the boundary inside cluster_client_timer_handler. The current-head probe captures that callback entry and the planned reconnect, both with and without retry accounting. Disconnect frees the active rate timer; fill_pipeline returns immediately after reconnect, handle_timer_event has no subsequent timer access, and the wrapper returns. Five exact-head cases (including delayed EXEC, request-budget and deadline controls) exit normally; descriptors remain5→5 and no listeners/threads remain. The same five inputs pass the prior1100 ASan/LSan binary with byte-identical lifecycle source, attributed as corroboration rather than a new-head sanitizer run. Full current-head sanitizer CI is still required.

The duplicate connection block and first-command scan can be refactored separately; this retains the existing non-transaction path and directly tested boundary lookup. The rate-limited probe is retained with the review evidence; a committed combination test remains useful follow-up coverage.

All final-head review and CI gates remain mandatory; merge will be squash only.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

bugbot run

Please review integration head cafd747. The automatic Cursor check skipped an unchanged patch; a fresh run is requested for this head.

Following the 19:11:54 Claude update: the processed baseline is intentional. At a drained standalone transaction boundary, generated and processed coincide. Disconnect uncounts dropped workload requests, and lost-MULTI skipping advances the rotation without generating another request. The earlier independent GDB control observed equality at all 24 planned reconnect boundaries, including the natural rate-timer/lost-block case. The integration preserves those production and regression-test blobs exactly; it does not relabel that earlier runtime probe as a new execution. The less-than guard protects unsigned subtraction defensively.

The duplicate reconnect block and first-command lookup remain localized to preserve the established non-transaction path; no new hot-path performance claim is made. The README wording describes the remaining partial request-budget limitation, which is still open as #647. The peer's error list is checked only after shutdown/server_close/join; it is a diagnostic append list rather than the multi-field transaction counters protected by the lock. I have left those nonblocking refactors/wording nits out of this integration.

Fresh validation: clean 17/17 units, 15/15 authenticated focused runtime tests, and all 832 tests assigned exactly once across two sanitizer shards. Commands, source identity and results. Seven focused reviews and full new-head CI remain mandatory.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit cafd747. Configure here.

@fcostaoliveira
fcostaoliveira merged commit 3ff7204 into master Oct 23, 2026
150 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

1 participant