-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DirectRaterLimiter::check_all does not error on exceeded cap #11
Comments
Thanks for reporting this issue (and for including a test case - that's really helpful)! I had to adjust it a bit so it would compile & then error: #[test]
fn errors_on_exceeded_cap() {
let lim = RateLimiter::direct(Quota::per_second(nonzero!(10u32)));
// This does not error even though we exceed the capacity.
assert_eq!(
Err(NegativeMultiDecision::InsufficientCapacity(10)),
lim.check_all(nonzero!(11u32))
);
} I guess we're seeing an off-by-one error somewhere! |
Yeppppp, this is definitely an off-by-one error in the |
antifuchs
added a commit
that referenced
this issue
Feb 1, 2020
This fixes #11: I'd missed that the "weight" variable is _additional weight_ that gets added to the first cell, so check_all (when given one more element than fit in the burst capacity) would return a "denied" result instead of an "insufficient capacity" result - effectively preventing futures from ever completing. Now, we treat additional weight as what it is: * rename "weight" to "additional_weight" to make it clear what is going on * Add a comment over the capacity check, clarifying the off-by-one error potential * Add a test about for more capacity-excession scenarios, including the off-by-one, to prevent regressions.
bors bot
added a commit
that referenced
this issue
Feb 2, 2020
12: Fix off-by-one error in check_all's capacity check r=antifuchs a=antifuchs This fixes #11: I'd missed that the "weight" variable is _additional weight_ that gets added to the first cell, so check_all (when given one more element than fit in the burst capacity) would return a "denied" result instead of an "insufficient capacity" result - effectively preventing futures from ever completing. Now, we treat additional weight as what it is: * rename "weight" to "additional_weight" to make it clear what is going on * Add a comment over the capacity check, clarifying the off-by-one error potential * Add a test about for more capacity-excession scenarios, including the off-by-one, to prevent regressions. Thanks to @jean-airoldie for discovering the bug & reporting it! Co-authored-by: Andreas Fuchs <asf@boinkor.net>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I correctly understand the
DirectRateLimiter::check_all
doc, it should error when an
greater than the initialmax_burst
when creating theQuota
is passed. However it is not the case:The text was updated successfully, but these errors were encountered: