Repository navigation
fix(cluster): prevent assertion abort on reconnect with --cluster-mode --reconnect-on-error (#377) - #378
Merged
Conversation
…377) cluster_client::connect() unconditionally pushed a new key_index_pool every time it was called. On the initial call that matched the single main connection in m_connections and the invariant held, but the reconnect path in shard_connection::handle_reconnect_timer_event re-enters connect() without clearing m_connections or m_key_index_pools — so the next call grew the pools vector by one and triggered: Assertion `m_connections.size() == m_key_index_pools.size()' failed. aborting the whole memtier_benchmark process the first time any worker thread had to reconnect under --cluster-mode --reconnect-on-error. Only push the main connection's key_index_pool on the first connect. Subsequent reconnects reuse the existing pool, keeping the parallel vectors aligned. Adds tests/test_reconnections.py::test_reconnect_cluster_mode_no_assertion that runs the cluster-mode workload, kills connections mid-run, and asserts memtier never aborts and no assertion line appears in stderr. Fixes #377 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
paulorsousa
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cluster_client::connect()idempotent so the reconnect path doesn't growm_key_index_poolsout of sync withm_connectionsand fireAssertion \m_connections.size() == m_key_index_pools.size()', which previously SIGABRT'd the wholememtier_benchmarkprocess the first time any worker thread had to reconnect under--cluster-mode --reconnect-on-error`.tests/test_reconnections.py::test_reconnect_cluster_mode_no_assertion) that runs the bug-triggering workload, kills connections mid-run viaCLIENT KILL TYPE normal, and asserts memtier never aborts.Root cause
cluster_client::connect()(cluster_client.cpp:109) unconditionally did:On the first call this matched the single main connection in
m_connections(assertion holds). Butshard_connection::handle_reconnect_timer_eventre-entersconnect()on every reconnect attempt without clearing either vector — som_key_index_poolsgrew by one each time whilem_connectionsstayed the same, and the next reconnect tripped the assertion.Fix
Only push the main connection's
key_index_poolon the first connect; reuse it on subsequent reconnects. Per-shard pools added later viacreate_shard_connection()are unchanged.Verification
Repro (before fix):
After fix: same workload + repeated kills runs to completion, all worker threads reconnect, no aborts.
Regression test: stashed the fix, rebuilt, ran the new test → fails with
exit_code == -6 (SIGABRT). Restored the fix, rebuilt, ran the new test → passes.Test plan
CLIENT KILL TYPE normaltest_reconnect_cluster_mode_no_assertionpasses against fixed binaryclang-format --dry-run --Werror cluster_client.cppcleanFixes #377
🤖 Generated with Claude Code
Note
Medium Risk
Touches core cluster reconnect bookkeeping; while small, mistakes could cause crashes or incorrect request routing during reconnect scenarios.
Overview
Prevents
memtier_benchmarkfrom aborting under--cluster-mode --reconnect-on-errorby makingcluster_client::connect()only create/push the main connection’skey_index_poolon the first connect, keepingm_key_index_poolsaligned withm_connectionsacross reconnects.Adds a cluster-only regression test (
test_reconnect_cluster_mode_no_assertion) that runs memtier with reconnect enabled, forcibly drops connections viaCLIENT KILL TYPE normal, and asserts the process exits without them_connections.size() == m_key_index_pools.size()assertion or SIGABRT.Reviewed by Cursor Bugbot for commit 35b4f03. Bugbot is set up for automated code reviews on this repo. Configure here.