Skip to content

fix: hash only source IP for consistent hash policy - #588

Open
areycruzer wants to merge 1 commit into
kubeedge:mainfrom
areycruzer:fix/source-ip-consistent-hash
Open

areycruzer wants to merge 1 commit into
kubeedge:mainfrom
areycruzer:fix/source-ip-consistent-hash

Conversation

@areycruzer

Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

The consistent-hash load balancer's useSourceIp mode hashed the full RemoteAddr() string (IP:port) instead of only the source IP. Because client source ports are ephemeral, the same client could be routed to a different backend on every new connection, defeating session stickiness and violating the Istio ConsistentHashLB.useSourceIp contract.

This change extracts only the host from the source address before hashing:

  • IPv4 and IPv6 (bracketed) addresses are handled via net.SplitHostPort, with a fallback for addresses without a port.
  • Empty or missing source addresses now return a descriptive error instead of hashing an ambiguous key.
  • The existing netConn.RemoteAddr() fallback behavior is preserved.

Regression tests prove the same source IP with different ephemeral ports now selects the same endpoint, for both IPv4 and IPv6, plus error cases for empty/malformed addresses.

Which issue(s) this PR fixes:

Fixes #587

Special notes for your reviewer:

Verified with go test ./pkg/loadbalancer -count=1 under Go 1.19 on Linux (the repository's pinned toolchain).

Does this PR introduce a user-facing change?:

Fixed consistent-hash load balancing with `useSourceIp`: the hash key now uses only the client source IP, so connections from the same client consistently reach the same backend regardless of ephemeral source port.

Signed-off-by: swyam sharma <swyam7@gmail.com>
Copilot AI lite review requested due to automatic review settings August 16, 2026 12:03
@kubeedge-bot kubeedge-bot added the kind/bug Categorizes issue or PR as related to a bug. label Aug 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@kubeedge-bot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: areycruzer
To complete the pull request process, please assign kevin-wangzefeng after the PR has been reviewed.
You can assign the PR to them by writing /assign @kevin-wangzefeng in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot

Copy link
Copy Markdown
Collaborator

Welcome @areycruzer! It looks like this is your first PR to kubeedge/edgemesh 🎉

@kubeedge-bot kubeedge-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consistent hash useSourceIp incorrectly includes source port

3 participants