Repository navigation
Conversation
Config.MaxRequestBurst is documented as "Set to 0 to use default (2x MaxRequestRate)", but NewRateLimitedHandler passed 0 straight to the token bucket. A bucket with capacity 0 never holds a token, so a Config that sets only MaxRequestRate rejected every request with 429. The CLI and YAML default (-1) had the same result for rates below 0.5 req/s, because int(rate*2) truncates to 0 there. Use 2x the rate, and at least 1, whenever the burst is unset, in both NewRateLimitedHandler and SetRateLimits. Rates of 0.5 req/s and above get the same burst as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
| @@ -373,7 +373,7 @@ func (config *Config) SetRateLimits(maxConcurrent int, maxRate float64, maxReque | |||
|
|
|||
| // Apply default: 2x rate when not explicitly configured or configured negative | |||
Collaborator
There was a problem hiding this comment.
I think we can remove this comment as well now since this logic is housed elsewhere.
Suggested change
| // Apply default: 2x rate when not explicitly configured or configured negative |
Collaborator
There was a problem hiding this comment.
Suggested change
| // maxRequestBurst: < 0 = use default rate based on maxRate, >=0 = must be greater than maxRate. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
Thanks for the review! Applied both suggestions in the latest commit; |
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 was wrong
The rate limiter rejected every request with 429 when its burst ended up at 0. That happened in two ways:
Config.MaxRequestBurstis documented as "Set to 0 to use default (2x MaxRequestRate)", andNewConfig()leaves it at 0. ButNewRateLimitedHandlerpassed the 0 straight to the token bucket. A bucket with capacity 0 never holds a token, so aConfigthat sets onlyMaxRequestRateturned away all traffic.-1),SetRateLimitsset it toint(maxRate * 2). For any rate below 0.5 req/s (for example--max-request-rate=0.25) that truncates to 0, with the same result.What changed
defaultRequestBurst(rate)inrate_limiter.go. It returns 2x the rate, and at least 1, for a positive rate. For a rate of 0 it returns 0, as before.NewRateLimitedHandleruses the helper whenMaxRequestBurst <= 0, so the documented default applies.SetRateLimitsuses the same helper instead ofint(maxRate * 2).Rates of 0.5 req/s and above get exactly the same burst as before. Explicit bursts are unchanged, and so is the existing check that an explicit burst must be greater than the rate.
How it was tested
Two new tests in
pkg/smokescreen/rate_limiter_test.go:TestRateLimitedHandler_DefaultBurst:MaxRequestRate: 5with the burst unset lets 10 requests through and limits the 11th.TestRateLimitedHandler_DefaultBurstLowRate:SetRateLimits(0, 0.25, DefaultMaxRequestBurst)gives a burst of 1. The first request passes and the second is limited.Both fail on
master(bc3bf31): every request gets 429, and the burst is 0. Both pass with this change.The rest of the CI checks were run locally by the agent (Go 1.27.2, and Go 1.27.1 for staticcheck), and all passed:
gofmt -l,go mod verify,go vet ./...,go test ./...,go test -race ./...,go test -race -tags=smokescreen_no_prometheus ./...,go test -race -tags=integration ./cmd/..., andstaticcheckv0.8.1 with the three tag sets from the lint job. The Go 1.26 matrix leg was not run locally.The
v2branch has the same code in both places. Happy to open a port there if that would help.AI disclosure
This change was prepared with an AI coding agent (Claude Code), including the tests and the local runs above. I am responsible for it and will answer review comments.
🤖 Generated with Claude Code