fix: avoid int32 overflow when maxTrafficWeight is large - #4923
Open
semx wants to merge 1 commit into
Open
Conversation
replicas and weights were multiplied as int32 before being widened, so a large maxTrafficWeight overflowed the product and the canary counts came out wrong. With maxTrafficWeight=100000000, a 43 replica rollout at 50% weight produced -21 canary replicas, and at 100% weight it produced 1 canary replica instead of 43. Widen the operands before multiplying, the way trafficWeightToReplicas already does. Signed-off-by: semx <7532921+semx@users.noreply.github.com>
|
Contributor
Published E2E Test Results 4 files 4 suites 3h 52m 55s ⏱️ For more details on these failures, see this check. Results for commit c3cd007. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4923 +/- ##
==========================================
- Coverage 85.12% 85.07% -0.06%
==========================================
Files 166 166
Lines 19238 19239 +1
==========================================
- Hits 16376 16367 -9
- Misses 2019 2024 +5
- Partials 843 848 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Published Unit Test Results2 584 tests 2 584 ✅ 3m 24s ⏱️ Results for commit c3cd007. |
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.



Fixes canary replica counts being computed from an overflowed
int32product whenmaxTrafficWeightis large.The problem
Several places multiply a replica count by a traffic weight while both are still
int32, and only widen the result afterwards:maxTrafficWeighthas no upper bound (the CRD only saysformat: int32), and the repo's own tests use100000000. At that scale the product exceedsmath.MaxInt32for quite ordinary replica counts, and the arithmetic wraps.approximateWeightedCanaryStableReplicaCountswithmaxWeight=100000000,maxSurge=0:A negative canary count at 50%, and a single canary replica when the rollout is fully shifted to canary.
checkReplicasAvailableis affected the same way: the overflowed product goes negative, soavailableReplicas < desiredReplicasis never true and it reports that there are enough replicas. With 43 replicas at 50% weight and zero of them available it returnstrue, which lets traffic shift to pods that are not ready.The threshold is
replicas * weight > MaxInt32, so withmaxTrafficWeight=100000000it starts at about 22 replicas.The fix
Widen the operands before multiplying.
trafficWeightToReplicasin the same file already does exactly this:The same shape is applied to
approximateWeightedCanaryStableReplicaCounts,weightDelta,checkReplicasAvailable, the dynamic-stable-scale weight intrafficrouting.go, and the actual-weight display inrollout_info.go. Behaviour for the defaultmaxTrafficWeight=100is unchanged — the existing table cases all still pass.Tests
Added cases to the existing tables. Both fail on
masterand pass with this change:TestApproximateWeightedNewStableReplicaCounts—expected: 22, actual: -21andexpected: 50, actual: 8TestCheckReplicasAvailableWithCustomMaxTrafficWeight— 43 replicas, 0 available, 50% weight must not report available