Repository navigation
fix(loadbalancer): avoid int overflow of uptime in warmup weight calculation - #8005
Merged
yuluo-yx merged 1 commit intoOct 24, 2026
Merged
Conversation
Aias00
approved these changes
Oct 23, 2026
Aias00
left a comment
Contributor
There was a problem hiding this comment.
LGTM. The overflow was real: (int) (System.currentTimeMillis() - timestamp) truncates the low 32 bits, so an upstream older than ~24.8 days could land back inside the warmup window and get a reduced weight. Widening uptime to long and only narrowing inside the uptime < warmup branch is safe because warmup is an int.
The regression tests are well chosen, especially fullWeightWhenUptimeLowBitsFallInWarmupTest, which pins the exact truncation case.
dmsolr
pushed a commit
that referenced
this pull request
Oct 25, 2026
Sync to current master to resolve the stable shenyu-integrated-test-http CI failure (CachePluginTest.testMemoryModle/testRedisModle). Root cause: this branch predated #8079, whose pre-fix CachedResponse.capture() refused to store any response carrying a Vary header, so the cached endpoint was never reused and both requests hit the backend. #8079 keys Vary responses on the selecting request headers instead. Also pulls in the divide/loadbalancer work (#8076, #7172, #7986, #8005, #7821, #8033, #8090). #7172 removeStaleUpstreams reconciles via removeFromMap/triggerRemoveOne, which republish the immutable healthy snapshot under the same lock, so the read-only snapshot model stays correct with no stale retained instances.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
AbstractLoadBalancer#getWeightcomputedint uptime = (int) (now - timestamp). The timestamp comes from the upstream'sdateCreatedor registration time, so for long-running upstreams the cast overflows:uptime > 0check fails, so full weight is returned and there is no visible impact.(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
uptimeaslongfor the comparison, and cast tointonly inside the warmup window.Tests
Added
AbstractLoadBalancerTestcovering: 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:
./mvnw clean install -Dmaven.javadoc.skip=true.