kubeedge / kubeedge/edgemesh

Consistent hash useSourceIp incorrectly includes source port

Open
#587 2 comments 0 reactions 1 assignee Claimed by @areycruzer View on GitHub
kind/bug
Dominant language
Go
Stars
293
Forks
145
PR merge metrics
No merged PRs in 30d

Description

**What happened**:

When an Istio `DestinationRule` selects `consistentHash.useSourceIp`, EdgeMesh hashes `srcAddr.String()` in `ConsistentHashPolicy.Pick`. The proxy and gateway pass a TCP remote address, whose string form contains both the client IP and ephemeral source port, for example `192.0.2.10:49152`.

Connections from the same client IP can therefore select different endpoints when their ephemeral ports differ. This defeats the source-IP session affinity requested by the policy.

**What you expected to happen**:

`useSourceIp` should hash only the source IP address, as specified by the Istio API. Connections from one IPv4 or IPv6 source must select the same endpoint regardless of source port.

**How to reproduce it (as minimally and precisely as possible)**:

1. Configure a `DestinationRule` with `trafficPolicy.loadBalancer.consistentHash.useSourceIp: true` and multiple endpoints.
2. Open two TCP connections from the same client IP using different ephemeral ports.
3. Observe that `pkg/loadbalancer/policy.go` uses each complete `IP:port` value as the ring key, allowing the two connections to resolve to different members.

A focused unit reproduction can construct two `net.TCPAddr` values with the same IP and ports that map to different ring members under the current complete-address keys, then call `ConsistentHashPolicy.Pick` for both.

**Anything else we need to know?**:

The Istio API documents `useSourceIp` as hashing the source IP address. The minimal correction is to preserve the existing `RemoteAddr()` fallback, parse the resolved address with `net.SplitHostPort`, hash only the host, and return contextual errors for missing or malformed addresses. Regression coverage should include IPv4, IPv6, missing input, and malformed input.

No semantic duplicate or open pull request touching `pkg/loadbalancer/policy.go` was found before filing.

**Environment**:

- EdgeMesh version: `main` at `cde4c95d68acfe35ad6db2887dce272d0f36c1bb`
- Kubernetes version: not deployment-specific; reproduced at the unit level
- KubeEdge version: not deployment-specific; reproduced at the unit level
- Go version: repository-supported Go 1.19

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.