Repository navigation
Reject truncated consistent hashing replica keys - #3585
Merged
Merged
Conversation
Check snprintf results before hashing replica keys in the default and Ketama policies. Reject formatting errors and truncated keys without partially updating the hash ring. Keep existing mappings for keys that fit the buffer. Cover key-length boundaries, batch additions, and disabled tag hashing for Murmur3, MD5, and Ketama.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The bounds checks address the invalid-length issue, and regression coverage exercises the affected policies and ring-update behavior.
Review effort: Balanced
Findings: None
What changed in this PR
Prevents bRPC’s consistent-hashing policies from hashing invalid or truncated replica keys.
Changes:
- Validate formatting results before hashing in default and Ketama policies.
- Add regression coverage for key-length boundaries, failed additions, mixed batches, and disabled tag hashing.
| File | Description |
|---|---|
| test/brpc_load_balancer_unittest.cpp | Tests all three hashing policies and rejection behavior. |
| src/brpc/policy/consistent_hashing_load_balancer.cpp | Rejects invalid key lengths before hashing. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
What problem does this PR solve?
Issue Number: N/A
Problem Summary:
The consistent hashing replica builders use the length returned by
snprintfeven when the formatted key does not fit the buffer. Oversizedserver tags can therefore produce an invalid key length for hashing.
What is changed and the side effects?
Changed:
replica policies, rejecting formatting errors and truncated keys.
boundaries, rejection without partial ring updates, mixed batch additions,
and oversized tags when tag hashing is disabled.
Side effects:
Request selection is unchanged.
existing mappings. When server tags participate in hashing, servers whose
generated keys exceed the existing buffer capacity are rejected rather
than hashing an invalid length. Batch additions still retain valid servers.
Check List: