Repository navigation
Fix cluster abort when a slot map refresh retires the connection handling it (#578) - #584
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. The root-cause write-up is easy to follow, and the table showing each half of the fix failing on its own is the kind of evidence that makes this easy to review. I went through the diff and have a couple of small questions, nothing blocking.
The test pins the exact scenario from #578, covers both the retry and no-retry variants, and is shown to fail on master, so it clears the regression-test bar this repo has set before (e.g. #364). The stats under-count around a retirement is disclosed and seems reasonable. Since this is cluster routing, a second look from whoever owns the cluster client would be good. The core fix looks solid to me. (would file this as a comment, not a formal block) |
…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]>
583f624 to
dc4daf5
Compare
|
Thanks for the review. Taking your points in order (fixes are in dc4daf5):
Wake-up vs the
Module docstring. Updated. It now covers both groups of tests and says the #578 slot-move tests need no replicas, with the Leftover slot layout /
The 5/5 figure. Replaced with measured rates. Each pair is failed runs / runs for the
🤖 Generated with Claude Code |
The last cycle of the #578 slot-move tests left the victim's slots on the seed primary. With --retry-on-error over TLS that occasionally (about 2% of runs) trips an unrelated, pre-existing redirect livelock and hangs the run until the test's timeout; it is tracked separately. Every cycle now retires the victim's connection, waits a second and then returns the slots, so the run still exercises the self-retire but ends on the original layout. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Addressed the build reviewer's TLS hang in 30deb73. The The hang itself is a separate, pre-existing livelock: a connection holding more than Local runs (failed / valid runs, RLTest, 3 shards):
🤖 Generated with Claude Code |
|
The separate redirect livelock that the final slot-move cycle avoids is tracked in #590, and its fix is in PR #591. #591 should merge after this PR (see the interaction review on #591). 🤖 Generated with Claude Code |
fill_pipeline() only ran its loop while the run was not finished. With --test-time, a MOVED that arrives after the deadline still asks for a CLUSTER SLOTS refresh, but the loop never ran, so the refresh was never sent and the retries in flight kept bouncing on MOVED forever, just as with a full pipeline. Once finished, keep running the loop for setup commands while responses are pending, and stop it before any new request is created. Tests: - test_moved_after_test_time_refreshes_slots: MOVED starts after --test-time=1 is up. It hung on the previous commit. - test_pipeline_depth_stays_at_cap: a batching peer checks that each connection holds exactly --pipeline requests, which catches a "size() > pipeline" off-by-one in the moved depth check. - The overfull-connection test also runs a burst variant, where the node answers CLUSTER SLOTS and everything queued behind it in one write (needs #584). It now checks Totals Count == --requests and bounds the MOVED count. Refs #590 Co-Authored-By: Claude Opus 5.5 <[email protected]>
fill_pipeline() only ran its loop while the run was not finished. With --test-time, a MOVED that arrives after the deadline still asks for a CLUSTER SLOTS refresh, but the loop never ran, so the refresh was never sent and the retries in flight kept bouncing on MOVED forever, just as with a full pipeline. Once finished, keep running the loop for setup commands while responses are pending, and stop it before any new request is created. Tests: - test_moved_after_test_time_refreshes_slots: MOVED starts after --test-time=1 is up. It hung on the previous commit. - test_pipeline_depth_stays_at_cap: a batching peer checks that each connection holds exactly --pipeline requests, which catches a "size() > pipeline" off-by-one in the moved depth check. - The overfull-connection test also runs a burst variant, where the node answers CLUSTER SLOTS and everything queued behind it in one write (needs #584). It now checks Totals Count == --requests and bounds the MOVED count. Refs #590 Co-Authored-By: Claude Opus 5.5 <[email protected]>
fill_pipeline() only ran its loop while the run was not finished. With --test-time, a MOVED that arrives after the deadline still asks for a CLUSTER SLOTS refresh, but the loop never ran, so the refresh was never sent and the retries in flight kept bouncing on MOVED forever, just as with a full pipeline. Once finished, keep running the loop for setup commands while responses are pending, and stop it before any new request is created. Tests: - test_moved_after_test_time_refreshes_slots: MOVED starts after --test-time=1 is up. It hung on the previous commit. - test_pipeline_depth_stays_at_cap: a batching peer checks that each connection holds exactly --pipeline requests, which catches a "size() > pipeline" off-by-one in the moved depth check. - The overfull-connection test also runs a burst variant, where the node answers CLUSTER SLOTS and everything queued behind it in one write (needs #584). It now checks Totals Count == --requests and bounds the MOVED count. Refs #590 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
In cluster mode, moving every slot off a live primary mid-run makes memtier retire that primary's connection. With
--retry-on-errorthe run then aborts:Without
--retry-on-error, the same move often ends the run withclient(s) stopped before reaching their stop condition.Root cause
-MOVED, sohandle_moved()makes that same connection sendCLUSTER SLOTS.process_response()loop.handle_cluster_slots()sees that the node owns no slots and callsdisconnect()on it, i.e. on the connection running the loop.disconnect()frees the bufferevent and empties the pipeline: with--retry-on-errorthe requests go to the replay queue (handed off by Resend held retries when a slot map refresh retires a connection #575), otherwise they are uncounted.parse_response()returns the replies still buffered behind theCLUSTER SLOTSreply (the resends of--retry-on-errorfollow it on that connection), andpop_req()pops an empty pipeline. Debug builds hit the assertion. Release builds use a garbagerequest*.The non-retry variant comes from the same retirement but by another route. Producers parked by
hold_pipeline()(in-flight budget) wait on the retired connection's pooled and in-flight work.handle_cluster_slots()drops that work, but no reply is left to make a parked producer runfill_pipeline()again. In gdb, every live connection of both clients was paused with nothing pending andgenerated == processed, so the event loop ran out of events.Fix
shard_connectionkeeps a disconnect counter thatdisconnect()bumps.process_response()notes it before parsing and stops once a handler has torn the connection down. It is a counter rather than a state check so that a disconnect followed by a reconnect inside the same handler is caught too. The remaining buffered replies have no request left to match:disconnect()already requeued or uncounted each one. The rest ofprocess_response()runs as after any loop exit (see the review reply for why that is safe).handle_cluster_slots()wakes every live connection withschedule_fill()whenever it retires a connection, as it already did for--multi-key-get. "Retires" includes a connection that was already disconnected, and requests thathand_off_replay_requests()drops: everything dropped there frees--requestsand in-flight budget.The #575 replay hand-off (
hand_off_replay_requests()/adopt_replay_request()) and the monitor and key-pool compensation in the retirement loop are not changed. The generated/processed accounting is unchanged too.--test-timeruns are fixed as well. Locally, master aborted 2/3 runs of a 12 s run with a slot move at 3 s; with this PR all 3 ran the full 12 s.Stats consequence: replies dropped after a self-teardown are not counted. The server did execute those commands, but memtier never matches their replies. With
--retry-on-errorthey are resent and counted once, on their final reply. Without it they are uncounted from the generated total, like any other request dropped bydisconnect(). Stats can therefore under-report work the server did around a retirement, by up to one pipeline per retired connection.Tests
tests/test_cluster_failover_retry.pygets two tests:--requestsrun with--pipeline 16. They then check rc, stderr and the exact op count.DELSLOTSRANGEon every node, old owner first, thenADDSLOTSRANGE+BUMPEPOCHon the new owner. If gossip handed the slots back in between,ADDSLOTSRANGEfails with "already busy"; the helper then deletes again and retries.--retry-on-error, the other without.Measured locally (RLTest, 3 shards, Redis 8.6.0, rebased on e4d14e8). Each cell is failed runs / runs, for the
--retry-on-errortest then the no-retry test:breakNotes on these numbers:
Each half of the fix is needed. Without the
breakthe retry test aborts every time. With only thebreak(the earlier revision), the no-retry test still failed 1/3.Standalone repro from the issue (3 primaries + 1 replica,
-n 2000000 --pipeline=16):--retry-on-error: master fa45424 aborted 3/4; this PR failed 0/4.Existing suites on this revision, all passing:
test_retry_on_error.py,test_reconnections.py,test_cluster_transaction.py,test_transaction_pipeline.py,test_mget_cluster.py,test_monitor_cluster.py,test_monitor_cluster_backpressure.py(52 tests)test_read_preference_failover.py,test_read_preference_transaction.pytest_retry_on_error.py,test_reconnections.py(18 tests)The previous revision also passed
tests_oss_simple_flow.py.Fixes #578
Affected versions
2.4.0 through 2.4.4: confirmed by running. Master: confirmed by running. 2.5.0 through 2.5.2: the code path is present, but the crash wasn't reproduced because another bug masks it.
--retry-on-error, added in 08cfc24 (feat(retry): --retry-on-error with bytes-snapshot resend + failed-keys log #381, first tag 2.4.0).🤖 Generated with Claude Code
Note
Medium Risk
Changes cluster topology retirement and the hot
process_response()loop; incorrect handling could still mis-account stats or stall producers, though scope is narrow and covered by new integration tests.Overview
Fixes cluster-mode runs that abort or stop early when a
CLUSTER SLOTSrefresh retires the same connection that is handling that reply (e.g. all slots moved off a live primary after-MOVED).shard_connectionincrementsm_disconnect_countondisconnect()andprocess_response()stops the parse loop once a handler tears the connection down, so leftover buffered replies are not paired with an emptied pipeline (avoids thepop_req()assertion with--retry-on-error).handle_cluster_slots()tracks whether any connection was retired andschedule_fill()on all live shards when that happens (not only for--multi-key-get), so producers parked on in-flight budget wake up and--requestscan finish without retry.Tests:
test_cluster_failover_retry.pyadds mid-run slot move cycles with pipeline depth, with and without--retry-on-error.Reviewed by Cursor Bugbot for commit 30deb73. Bugbot is set up for automated code reviews on this repo. Configure here.