Repository navigation
Reconnect only the dropped cluster connection, and only once - #560
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. The write-up of how the hang was found makes the two paths easy to follow. I like that the new test is shown hanging on master (rounds 0–7 of 10) and passing with the fix. That's the bar this kind of fix should meet. A few questions:
The core fix looks right to me, and the |
c9f4ebc to
3702b7a
Compare
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 3702b7a. Configure here.
dab76b5 to
8c374d1
Compare
A shard connection's reconnect timer called connect(), which in cluster mode reconnects the main connection. That discarded main's in-flight requests, which stayed counted as pending, so the run never ended (#558). A CLUSTER SLOTS refresh could also reconnect a shard connection while its own reconnect timer was pending, and the timer then reconnected the live connection, discarding its requests the same way. Add connections_manager::reconnect(conn_id). Its default reconnects the main connection as before. In cluster mode it leaves a dropped shard connection to a CLUSTER SLOTS refresh over the main connection, which it wakes if idle: the refresh reconnects the shard with its current role, or not at all if the node left the cluster. A refresh leaves a connection whose reconnect timer is pending to that timer, so the backoff and --max-reconnect-attempts still apply during a failover, and reconnect() does nothing to a connection that is no longer disconnected. The no-route spin guard now yields unless a primary is ready to serve requests, not just connected: during a failover the live primaries can all be waiting for a CLUSTER SLOTS reply, which only the event loop reads, so the worker spun forever instead. Fixes #558. Co-Authored-By: Claude Opus 5.5 <[email protected]>
8c374d1 to
49d115e
Compare

Fixes #558.
Problem
In cluster mode, a live connection could be connected again. That frees its bufferevent and opens a fresh socket, while its in-flight requests stay in the pipeline and in the pending count. Their bytes are lost, so:
disconnect_all()is never reached and memtier never exits.Two paths did this:
connect(), which always reconnects the main connection, whatever its state.Fix
connections_manager::reconnect(conn_id). Standalone clients keep reconnecting their only connection.cluster_client::reconnect()reconnects the dropped connection to its own endpoint and requests a slot map refresh over the main connection (which the old path got as a side effect). It does nothing for a connection that is no longer disconnected.shard_connection::connect()cancels a pending reconnect timer.How it was found
From CI, with temporary diagnostics (since removed): on a hang, the test dumped every thread's backtrace and, via gdb, each client's counters and each connection's state, buffers, pipeline and key pools, plus
ssfor both TCP ends.epoll_waitwith no timers.Testing
test_cluster_run_exits_with_reconnects_pending(cluster only): kills client connections on all masters around the--test-timedeadline, 10 rounds with varied timing, and fails if memtier doesn't exit.🤖 Generated with Claude Code
Note
Medium Risk
Changes cluster reconnection and CLUSTER SLOTS refresh coordination during failovers; incorrect behavior could still strand pending requests or delay topology recovery, but scope is limited to
--reconnect-on-errorcluster paths with new regression coverage.Overview
Fixes cluster-mode hangs (#558) where reconnecting a live socket left in-flight requests counted as pending on a new connection that never sent them, so the benchmark never reached shutdown.
Reconnect path: Adds per-connection
connections_manager::reconnect(conn_id). Shard timers call that instead of client-wideconnect(), which used to always reopen the main connection. For a dropped shard,cluster_client::reconnect()avoids redialing the main (and losing its pipeline); it wakes the main connection to refresh topology via CLUSTER SLOTS when appropriate. Successfulconnect()clears a pending reconnect timer; CLUSTER SLOTS skips immediate redial whenis_reconnect_pending()so backoff and max-attempt limits are honored.Failover spin guard: When routing is wedged,
hold_pipelinetreats a primary as “live” only ifis_ready_for_reads(), not merely TCP-connected, so the event loop can process CLUSTER SLOTS during failover.Test: New cluster integration test kills client connections near
--test-timeand asserts memtier still exits (skipped on TLS; #562).Reviewed by Cursor Bugbot for commit 49d115e. Bugbot is set up for automated code reviews on this repo. Configure here.