Conversation
Benchmark Results |
lprnmns
marked this pull request as ready for review
August 31, 2026 11:15
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
When a custom LimitCounter returns an error, RespondOnLimit invokes the configured error handler and then invokes the configured rate-limit handler as if the request had exceeded its limit. This can append a second response body and misrepresent a backend failure as HTTP 429.
Fix
Route the shared limit check through a private result that distinguishes a limit decision from a counter error. On counter errors, call only WithErrorHandler; preserve the existing boolean behavior and normal rate-limit response path.
Tests
go test -run TestRespondOnLimit_CounterErrorUsesErrorHandlerOnly -count=1— passedgo test -v ./...— passedgo test -race -count=1 ./...— passedgo vet ./...— passedgo build -v ./— passedgo test -run '^$' -bench=. -count=1 ./...— passed_example:go build -v ./,go test -v ./..., andgo test -race -count=1 ./...— passedgofmt -d limiter.go limiter_error_test.goandgit diff --check— cleanValidated with the repository-requested Go 1.24.1 toolchain.
Compatibility
The public OnLimit and RespondOnLimit signatures and return behavior are unchanged. Only counter-error handling is separated from the normal rate-limit response path; the local backend and normal 429 behavior are unchanged.
Related issue
Independent reproduction; no exact current issue or pull request was found.