Aias00 opened a new issue, #6891:
URL: https://github.com/apache/shenyu/issues/6891

   ## Description
   `LeastActiveLoadBalance.countMap` (a `ConcurrentHashMap<String, Long>`) 
accumulates an entry for every distinct `Upstream.buildDomain()` (protocol+url) 
ever seen. New domains are added. The map is read to find the minimum-count 
domain and the selected domain's count is incremented. There is NO removal 
path: when an upstream is removed from the upstream list (e.g. auto-scaling 
down, upstream reconfiguration), its `countMap` entry persists indefinitely. 
Unlike `RoundRobinLoadBalancer` which has a `recyclePeriod`-based cleanup, 
`LeastActiveLoadBalance` has no eviction logic at all. The filter at line 50 
(`domainMap.containsKey(entry.getKey())`) prevents stale entries from being 
selected, but they still occupy memory and are iterated on every `doSelect` 
call.
   
   ## Location
   - 
`shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/spi/LeastActiveLoadBalance.java:37,44-46,55`
   
   ## Impact
   Slow memory leak proportional to the number of distinct upstream URLs 
observed over the gateway's lifetime. In environments with dynamic upstream 
churn (container orchestration, blue-green deploys, ephemeral instances), 
`countMap` grows without bound. Also, the `entrySet().stream()` scan over stale 
entries on every request adds O(n) overhead where n includes all historical 
domains.
   
   ## Suggested fix
   After building `domainMap` in `doSelect`, remove `countMap` keys not present 
in `domainMap`: `countMap.keySet().retainAll(domainMap.keySet())` (before the 
min-selection), or add periodic eviction like `RoundRobinLoadBalancer`'s 
recycle logic.
   
   ## Related existing
   None — distinct from "p2c inflight leak" (which covers `P2cLoadBalancer`'s 
`inflight` counter, a different stat field in a different balancer). The 
LeastActive `countMap` unbounded-growth issue is not mentioned in any baseline 
entry or scan2 doc.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to