Fix integer division in failed-service-start notification heuristic#14815
Open
fethij wants to merge 1 commit into
Open
Fix integer division in failed-service-start notification heuristic#14815fethij wants to merge 1 commit into
fethij wants to merge 1 commit into
Conversation
hasRepeatedFailedServiceStarts compared the failure ratio against
serviceStartFailurePercentage (a Float, default 0.5), but computed the
ratio with integer division:
failures.size / (failures.size + successes.size)
Since failures.size is always <= the total, this integer division
evaluates to 0 in every case except when there are zero successes, where
it is 1. As a result the check only ever passes at a 100% failure rate
rather than the configured percentage, so the heuristic effectively never
detects users with a mixed (e.g. 50-99%) FCM service-start failure rate.
Convert the numerator to Float so the comparison uses the intended
fractional failure rate.
Contributor
|
Thanks, this will go out in 8.14. |
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.
Problem
SlowNotificationHeuristics.hasRepeatedFailedServiceStarts()decides whether a user is failing to start the FCM service too often by comparing the failure ratio againstserviceStartFailurePercentage(aFloat, default0.5). However, the ratio is computed with integer division:Both
failures.sizeandsuccesses.sizeareInt, sofailures.size / (failures.size + successes.size)is integer division. Becausefailures.sizeis always<=the total, this evaluates to:0whenever there is at least one success (i.e. any mixed ratio), and1only when there are zero successes (100% failures).Comparing that integer result against
0.5fmeans the branch only ever passes at a 100% failure rate, never at the configured 50% (or any other fractional threshold). In practice the failed-service-start signal of the delayed-notifications heuristic is dead for the realistic case of a user who fails, say, 50–99% of service starts.The sibling heuristics (
isFailingToDrainQueue,hasLongMessageLatency) compare raw counts/latencies, so they are unaffected — this is the only place a fractional rate is computed.Fix
Promote the numerator to
Floatso the comparison uses the intended fractional failure rate:Division by zero is not a concern here: an earlier guard returns when
(successes.size + failures.size) < minimumEventCount(default10).Notes
One-line change, no behavior change for the 100%-failure case; it now also correctly triggers for the intended fractional thresholds.