Repository navigation
fix(cluster): defensive clamp on m_reqs_generated subtraction at three sites - #437
Merged
Merged
Conversation
… sites PR #399 introduced a >= clamp at hold_pipeline; the three sibling sites (connect_shard_connection, handle_cluster_slots, handle_moved) subtract empty_staged.size() with no such guard. Today the invariant -- entries in empty_staged are pre-decrement -- holds, but a refactor could break it silently. Matching the pattern makes the invariant explicit and future-proofs against subtle underflow to 2^64. Refs: 2.4 review #12 (Review 1 + Review 16). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
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.cpp(connect_shard_connectionL244,handle_cluster_slotsretire-shard branch L504,handle_movedL1070) subtractempty_staged.size()fromm_reqs_generatedwith no underflow guard.hold_pipelinefor the same reason; this PR matches that pattern at the three sibling sites.empty_stagedare popped beforem_reqs_generatedis decremented) prevents underflow, but it is undocumented. A future refactor could silently wrapm_reqs_generatedto 2^64 and permanently wedge a--requests-bounded run.Fix
Each bare subtraction is replaced with:
An inline comment at each site documents the invariant and references
hold_pipelineas the canonical pattern.Test plan
autoreconf -ivf && ./configure && make -j— clean build, no new warnings.--monitor-inputand trigger topology changes (MOVED, slot rebalance, shard reconnect) to confirm no hang with--requests.empty_stagedis empty (the common path).Refs: Review 16 (analysis that the subtraction sites are safe today but unguarded).
🤖 Generated with Claude Code
Note
Low Risk
Small defensive accounting change in cluster client teardown paths; no auth, protocol, or routing logic changes.
Overview
When cluster topology or shard state clears staged monitor queues, the benchmark already subtracts those entries from
m_reqs_generatedso--requestsruns do not wait for responses that will never arrive.This change replaces three unchecked subtractions in
cluster_client.cpp—inconnect_shard_connection, the retire-shard path inhandle_cluster_slots, andhandle_moved—with the same defensive clamp used inhold_pipeline: subtract at most the current counter value so unsigned underflow cannot wrapm_reqs_generatedand wedge a bounded run. Inline comments document the invariant and point tohold_pipelineas the canonical pattern.Behavior on today's code paths should be unchanged; the guard is for future refactors that might double-compensate or skew the counter.
Reviewed by Cursor Bugbot for commit cef80e8. Bugbot is set up for automated code reviews on this repo. Configure here.