Duansg opened a new pull request, #8005:
URL: https://github.com/apache/shenyu/pull/8005

   ### What
   
   `AbstractLoadBalancer#getWeight` computed `int uptime = (int) (now - 
timestamp)`. The timestamp comes from the upstream's `dateCreated` or 
registration time, so for long-running upstreams the cast overflows:
   
   - After ~24.8 days, uptime becomes negative. The `uptime > 0` check fails, 
so full weight is returned and there is no visible impact.
   - After ~49.7 days (2^32 ms), the low 32 bits fall into `(0, warmup)` again. 
The upstream's weight drops to near 1 and ramps back up over the default 
10-minute warmup. This repeats every 49.7 days.
   
   ### How
   
   Keep `uptime` as `long` for the comparison, and cast to `int` only inside 
the warmup window.
   
   ### Tests
   
   Added `AbstractLoadBalancerTest` covering: within warmup, after warmup, 
uptime > `Integer.MAX_VALUE`, and uptime = 2^32 ms + 5 min. Without the fix, 
the last case fails (`expected: <100> but was: <50>`).
   
   Make sure that:
   
   - [x] You have read the [contribution 
guidelines](https://shenyu.apache.org/community/contributor-guide).
   - [x] You submit test cases (unit or integration tests) that back your 
changes.
   - [x] Your local test passed `./mvnw clean install 
-Dmaven.javadoc.skip=true`.


-- 
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