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

   ### Is there an existing issue for this?
   
   - [x] I have searched the existing issues
   
   ### Current Behavior
   
   `AbstractLoadBalancer.select` returns immediately for a singleton candidate 
list. This bypasses `P2cLoadBalancer.doSelect`, including its inflight 
increment. However, the normal Divide P2C completion callback still decrements 
the selected upstream's inflight. Repeated singleton requests therefore make 
the counter negative, and P2C subsequently uses that negative value in its load 
calculation.
   
   This affects single-upstream deployments and requests where filtering leaves 
only one eligible upstream. The explicit half-open probe path has its own 
increment and is not the path described here.
   
   ### Expected Behavior
   
   Pair start/completion accounting even when selection is short-circuited for 
a singleton list. A completed request must not leave a negative or leaked 
counter.
   
   ### Steps To Reproduce
   
   Configure Divide with `p2c` and one healthy upstream, then complete two 
requests. The following reproduces the selection plus the decrement performed 
by Divide's completion callback:
   
   ```java
   var upstream = Upstream.builder().protocol("http://";).url("a:80")
           .weight(100).status(true).build();
   var balancer = new P2cLoadBalancer();
   for (int i = 0; i < 2; i++) {
       balancer.select(List.of(upstream), new LoadBalanceData());
       upstream.getInflight().decrementAndGet(); // Divide responseTrigger
   }
   System.out.println(upstream.getInflight().get()); // observed: -1
   ```
   
   This minimal reproduction was executed against the commit below; the initial 
counter is 1.
   
   ### Anything else?
   
   - Singleton shortcut: 
https://github.com/apache/shenyu/blob/862f5e37e894bd8cef85ef540a8629f313e9ecdf/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/spi/AbstractLoadBalancer.java#L41-L48
   - Increment bypassed by the shortcut: 
https://github.com/apache/shenyu/blob/862f5e37e894bd8cef85ef540a8629f313e9ecdf/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/spi/P2cLoadBalancer.java#L73
   - Unconditional completion decrement: 
https://github.com/apache/shenyu/blob/862f5e37e894bd8cef85ef540a8629f313e9ecdf/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/DividePlugin.java#L215-L217
   - #6733 concerned cancellation cleanup. This issue remains with the current 
`doFinally` cleanup because the corresponding increment is skipped.
   
   ### 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]

Reply via email to