Repository navigation
Open
Labels
type: bugSomething isn't workingSomething isn't working
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
RoundRobinLoadBalancer keeps its smooth weighted round-robin state in methodWeightMap, keyed only by the URL of the first upstream in the list:
String key = upstreamList.get(0).getUrl();
ConcurrentMap<UpstreamIdentity, WeightedRoundRobin> map = MapUtils.computeIfAbsent(methodWeightMap, key, k -> new ConcurrentHashMap<>(16));The key carries neither the selector nor the whole upstream set. Consequences:
- Two selectors whose upstream lists start with the same upstream share one
WeightedRoundRobinperUpstreamIdentity. Selections in one selector change thecurrentcounters, and therefore the next pick, of the other. - If the shared upstream has a different weight in the two selectors, every alternation hits
weight != weightedRoundRobin.getWeight()(L61-L64) andsetWeightresetscurrentto 0 (L117-L120), so that node's counter is reset continuously. - The shared map holds the union of both lists, so
upstreamList.size() != map.size()(L74) is true on every call. Each call that winsupdateLockcopies the whole map and replaces it inmethodWeightMap. - Reordering a selector's upstream list moves its state to a different key. The previous state is never removed from
methodWeightMap, because recycling only runs inside the map of the current key.
Expected Behavior
Round-robin state is isolated per selector, or per complete upstream set. The configured weights determine the traffic ratio of each selector independently of other selectors.
Steps To Reproduce
- Use the same
RoundRobinLoadBalancerinstance (it is an SPI singleton). - Define list S1 = [A (weight 1), B (weight 9)] and list S2 = [A (weight 9), C (weight 1)], where A has the same URL in both.
- Call
select(S1, data)andselect(S2, data)alternately, for example 10,000 times each. - Count the picks per upstream for each list. The ratios differ from 1:9 and 9:1, whereas running each list alone in a fresh balancer gives the configured ratio.
Environment
ShenYu version(s): master @ 9dd9a12fbDebug logs
No response
Anything else?
Suggested fix: key the state by the full ordered identity list, the way HashLoadBalancer keys ringCache with List.copyOf(ringKey), or pass a selector id through LoadBalanceData and key by it. This issue is different from #8327, which fixed weight-accumulation overflow.
Found by static code review; I have not yet run the reproduction above.
Metadata
Metadata
Assignees
Labels
type: bugSomething isn't workingSomething isn't working
Activity
konlue commentedon Nov 12, 2026
/assign
[ISSUE apache#8441] Precompute the upstream identity marker key