Repository navigation
Wake peers when a replica finishes a CLUSTER SLOTS refresh - #605
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this, the root-cause write-up and the mutation table make it easy to follow. Moving the two READONLY loops into I went through the teardown paths, since A couple of small things, neither blocking:
The fix itself looks solid to me. Since this is cluster routing / hold_pipeline territory, a second look from whoever owns that path would still be good. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b3c2521. Configure here.
b3c2521 to
9f92196
Compare
Under --read-preference=secondary (with GETs in the ratio),
secondaryPreferred or nearest, hold_pipeline() holds every connection
while any replica is connected but not ready for reads. A replica with a
CLUSTER SLOTS refresh in flight is in that state. Peers were woken when a
replica finished its READONLY handshake, but not when it finished a
refresh. A held connection with nothing left to read then stayed idle
with requests queued in its key index pool, and a --requests run stopped
short ("client(s) stopped before reaching their stop condition").
Wake peers when a replica connection commits a CLUSTER SLOTS refresh, and
move the wake loop the READONLY paths already used into wake_peers().
Fixes #602
Co-Authored-By: Claude Opus 5.5 <[email protected]>
9f92196 to
7029fcd
Compare
hold_pipeline() holds every connection while a replica is connected (or reconnecting) but not ready for reads. The previous commit wakes them when a replica finishes a CLUSTER SLOTS refresh. A replica connection that drops or fails to reconnect instead leaves that state too, and nothing woke them then either, so a run whose replica went away during a refresh or a reconnect attempt hung. disconnect() now wakes peers for replica connections, which also covers the "leaving connection dead and continuing" path. handle_cluster_slots() can also promote this connection to a primary, so the refresh handler now checks the role it had before the reply. Tests: the refresh test now mixes in a SET so that primary connections have queued work too, waits until every node lists every replica in CLUSTER SLOTS before it starts, and checks Totals Count. A new test advertises one replica at a proxy that drops it mid-run and refuses reconnects, and checks that the run completes with the requested count. Fixes #602 Co-Authored-By: Claude Opus 5.5 <[email protected]>
7029fcd to
0d07017
Compare
|
Thanks. Point by point, against head 0d07017:
🤖 Generated with Claude Code |

Problem
With
--cluster-mode --read-preference secondary(alsosecondaryPreferred/nearest, without--read-preference-fallback=primary), connections held while a replica wasn't ready for reads could be left held for good. A--requestsrun then stopped short with "client(s) stopped before reaching their stop condition" (exit 1), hung until the connection-stage supervisor aborted it (exit 2), or hung outright. That happened in two cases:--command-is-read(replicas answer-READONLY, and each rejection triggers a refresh), master stalls 10/10 runs. ASETmarked--command-is-read(replicas answer-MOVED) stalls 2/10.Root cause
cluster_client::hold_pipeline()holds every connection while any replica is connected (or connecting) but notis_ready_for_reads(). A replica with a refresh in flight or a reconnect in progress is in that state. Peers were woken only when a replica finished its READONLY handshake. Neither a completed refresh nor a disconnect woke them. A held connection with nothing left to read is never called again, and the requests already queued in itsm_key_index_poolsare never sent.Fix
shard_connection::wake_peers()callsschedule_fill()on every other connected connection. It's the loop both READONLY reply arms already had, moved into a helper. The fill is deferred to the event loop.handle_cluster_slots(), because that call can promote this connection to a primary (Cursor Bugbot).disconnect()wakes peers for replica connections, after the existinghandle_connection_disconnect()notification. That also covers the "leaving connection dead and continuing" path inattempt_reconnect(), which goes throughdisconnect(). Waking during teardown is harmless:disconnect()cancels a pending deferred fill, and the destructor frees it.Tests
In
tests/test_read_preference_modes.py(-t 2 -c 4 --pipeline 4, cluster with replicas):test_read_preference_replica_refresh_wakes_peers: the EVAL write script with--command-is-read, plus--command=SET __key__ y, so primary connections have queued work too.--read-preference=secondary,-n 2000. Asserts exit 0 and TotalsCount== 16000.test_read_preference_replica_disconnect_wakes_peers: the cluster advertises one replica at a local proxy (cluster-announce-port). The proxy drops the replica's connection after 200 client writes and then refuses connections. Built-in--ratio=1:1,--reconnect-on-error,-n 2000. Asserts that the proxy dropped the connection, exit 0, and TotalsCount== 16000. Skipped under TLS.Local RLTest (
--env oss-cluster --shards-count 3 --use-slaves), on top of origin/master 013cb85:wake_peers()loop starts ati = 1wake_peers()wakes replica peers onlydisconnect()The previous PR head (refresh wake only), on the older base f548ae7: refresh test 4/5 pass, disconnect test 5/5 FAIL. The whole
test_read_preference_modes.pypasses 10/10 with this branch.An independent reviewer run of the disconnect test's scenario: master hung 3/3 at 93% (14904 of 16000 ops); this branch finished 3/3 with
Count16000.Manual, local 3+3 cluster: the EVAL/SET stall above went from 10/10 and 2/10 on master to 0/10. With a proxy that drops a replica on its CLUSTER SLOTS and then refuses connections (
--reconnect-on-error), master and the previous head hang 3/3 and this branch completes 3/3.Related
--read-preference-fallback primary --pipeline 16). That's a different hang on the same refresh path, and the two PRs complement each other. Don't send a second CLUSTER SLOTS while one is in flight #618 stops the duplicate refresh; this PR wakes the connections held while a replica refreshes or goes away. A proxy that drops a replica once and lets it reconnect still hung 1 run in 33 with this branch alone and 0 in 35 with Don't send a second CLUSTER SLOTS while one is in flight #618 applied on top, which fits Cluster --read-preference: a second CLUSTER SLOTS sent while one is in flight wedges the connection; run hangs #617.Fixes #602
Affected versions
The hold/wake gap dates from ee757e7 (#456, first tag 2.5.0), which added the warming gate and the READONLY-only wake. So 2.5.0–2.5.2 and master. Up to 2.5.2 it was masked, because the stalled worker was silently restarted: 2.5.2 exits 0 but writes a garbage negative
Total durationin 3/3 runs. 7a6394e (#546, master only, found by bisect) made it fail visibly. Confirmed by running on master and 2.5.2; 2.5.0–2.5.1 derived from history.🤖 Generated with Claude Code
Note
Medium Risk
Changes cluster read-preference pipeline gating and wake timing on replica topology/disconnect paths; incorrect wakes could affect throughput or ordering, but scope is limited to secondary read modes and deferred fills.
Overview
Fixes hangs under
--read-preferencesecondary modes whenhold_pipeline()blocks all connections while a replica is not ready for reads (#602).Adds
shard_connection::wake_peers()toschedule_fill()on every other connected peer (same logic previously duplicated on READONLY success/failure). Peers are now woken when a replica finishes a committed CLUSTER SLOTS refresh (role captured beforehandle_cluster_slots()can promote it) and when a replica disconnects (after routing is notified). READONLY paths call the helper instead of inline loops.Tests: two cluster RLTests in
test_read_preference_modes.py—replica slot-map refresh via EVAL-as-read + SET, and a dropping TCP proxy on a replica with--reconnect-on-error—both assert the run completes with full request counts; workloads wait for consistent CLUSTER SLOTS and use short timeouts to catch regressions.Reviewed by Cursor Bugbot for commit 0d07017. Bugbot is set up for automated code reviews on this repo. Configure here.