ratelimits: improve disabled limit handling #7803
Merged
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.
In the FailedAuthorizations limits, there was code that intentionally ignored errLimitDisabled errors (
errors.Is(err, errLimitDisabled)
). However, that that resulted in those functions later using a returnedlimit
value that was invalid (i.e. its zero value). That happened to trigger some later checks in validateTransaction. Specifically this check failed:When txt.limit.Burst is zero, this will always fail.
This problem doesn't really show up in prod, where all the limits are configured. But it showed up in tests, specifically TestPerformValidation_FailedValidationsTriggerPauseIdentifiersRatelimit, where the limits are constructed using a simplified config that leaves most of them disabled.
In this change, I tried to make handling of errLimitDisabled more consistent, and always return an allow-only transaction as early as possible instead of falling through the error condition.
Where that wasn't possible, I used a boolean to record whether the result of
builder.getLimit()
was valid before referencing any of its fields.I also added some "shouldn't happen" errors to catch this problem earlier if it recurs.
I removed some "skip disabled limit" comments because those say "what the code does" (which the code also says), not "why the code does it".
Fixes the test failures in #7797.