This PR updates the consistent hashing logic to use the remote address (RemoteAddr) of a connection instead of the local address (LocalAddr). The change addresses the following issues:
When a new connection is opened, LocalAddr points to the gateway address, while RemoteAddr correctly points to the client’s source IP. The previous use of LocalAddr caused issues, such as always directing traffic to the same database.
The fallback behavior now utilizes the full remote address (IP:port) as the key when useSourceIP is set to false. This change fixes the issue where the useSourceIP is disabled, as the remote address has a random port each time, making the key different.
Additionally, this PR:
Updates comments to clarify the changes in hashing logic.
Modifies test cases in consistenthash_test.go to mock RemoteAddr instead of LocalAddr and ensure the correct behavior is tested.
Development Checklist
[X] I have added a descriptive title to this PR.
[X] I have squashed related commits together.
[X] I have rebased my branch on top of the latest main branch.
[X] I have performed a self-review of my own code.
[X] I have commented on my code, particularly in hard-to-understand areas.
[X] I have added docstring(s) to my code.
[ ] I have made corresponding changes to the documentation (docs).
[ ] I have updated docs using make gen-docs command.
Description
This PR updates the consistent hashing logic to use the remote address (RemoteAddr) of a connection instead of the local address (LocalAddr). The change addresses the following issues:
useSourceIP
is set tofalse
. This change fixes the issue where the useSourceIP is disabled, as the remote address has a random port each time, making the key different.Additionally, this PR:
Development Checklist
make gen-docs
command.Legal Checklist