Aias00 opened a new issue, #7972:
URL: https://github.com/apache/shenyu/issues/7972
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Current Behavior
`LeastActiveLoadBalance` increments a private count on selection but never
decrements it when a request terminates. Each entry starts at `Long.MIN_VALUE`.
Consequently, this compares cumulative selections rather than concurrent active
requests. A newly added upstream receives consecutive requests until its
counter catches up with existing upstreams, irrespective of its outstanding
work. Weight and warmup do not protect the new node in this selection path.
### Expected Behavior
Compare outstanding requests, release accounting on
success/error/cancellation, and avoid sending a catch-up burst to a newly added
node.
### Steps To Reproduce
Using the compiled loadbalancer classes:
```java
var data = new LoadBalanceData();
var a =
Upstream.builder().protocol("http://").url("a:80").weight(100).status(true).build();
var b =
Upstream.builder().protocol("http://").url("b:80").weight(100).status(true).build();
var c =
Upstream.builder().protocol("http://").url("c:80").weight(100).status(true).build();
var balancer = new LeastActiveLoadBalance();
for (int i = 0; i < 100; i++) {
balancer.select(List.of(a, b), data);
}
int newNodeHits = 0;
for (int i = 0; i < 50; i++) {
if (balancer.select(List.of(a, b, c), data) == c) {
newNodeHits++;
}
}
System.out.println(newNodeHits); // observed: 50
```
The first 100 selections can represent already-completed requests:
completion cannot change the private count. This reproduction was executed
against the commit below.
### Anything else?
Source:
https://github.com/apache/shenyu/blob/862f5e37e894bd8cef85ef540a8629f313e9ecdf/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/spi/LeastActiveLoadBalance.java#L48-L101
Please add regression coverage for slow outstanding requests, completed
requests and adding an upstream after a long-running gateway has accumulated
selections.
### Environment
- ShenYu: master, 2.7.2-SNAPSHOT
- Commit: `862f5e37e894bd8cef85ef540a8629f313e9ecdf`
- Java 17
--
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]