Repository navigation
fix: the rate limiter must stop the request, not relabel it - #128
Merged
Merged
Conversation
RateLimitMiddleware set a 429 and returned, with a comment saying Crow
would handle completion. Crow's middleware chain short-circuits only on
res.is_completed() (crow/middleware.h:151), and only res.end() sets that
flag - so the request carried on. Auth ran, the SQL executed, and the
result set was appended to the 429 body.
Measured against the shipped binary, endpoint limit of 2:
request 1: 200 {"data":[{"marker":"leaked-row"}]}
request 2: 200 {"data":[{"marker":"leaked-row"}]}
request 3: 429 Rate limit exceeded. Try again later.{"data":[{"marker":"leaked-row"}]}
request 4: 429 Rate limit exceeded. Try again later.{"data":[{"marker":"leaked-row"}]}
So the limiter did none of the two things it exists for: it did not shed
load - every rejected request still paid for auth and the full query - and
it did not withhold the data, handing back the rows it had just refused in
the body of the refusal.
After: requests 3 and 4 return the message alone, and the query never runs.
The fix is res.end(). The tests are an integration suite rather than a
unit test of the middleware, deliberately: the defect lives in the
interaction between flAPI's middleware and Crow's chain, and a unit test
of the middleware in isolation passes against the broken code.
Four cases: a rejected request returns no rows, the limit holds for
subsequent requests, requests within the limit are untouched, and the 429
still carries Retry-After and X-RateLimit-Limit (RFC 6585) - end() must
not cost the headers set before it.
Found by an agent-crew review of the request hot path and verified against
a running server. A separate defect found while confirming it - the global
rate_limit block is documented, parsed, and read by nothing - is filed as
#127 rather than fixed here, because making it live starts returning 429s
to deployments that are unlimited today.
765 unit tests, 338 standalone integration tests.
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.
The bug
RateLimitMiddlewareset a 429 and returned, with a comment asserting Crow would handle completion:Crow's chain short-circuits only on
res.is_completed()(crow/middleware.h:151), and onlyres.end()sets that flag. So the request carried on: auth ran, the SQL executed, and the result set was appended to the 429 body.Measured against the shipped binary
Endpoint limit of 2 per 60s:
The limiter did neither of the two things it exists for:
After the fix, requests 3 and 4 return the message alone and the query never runs.
The fix
res.end(). One line.Testing
Integration tests against the real binary, deliberately not a unit test of the middleware: the defect lives in the interaction between flAPI's middleware and Crow's chain, and a middleware unit test passes against the broken code.
Four cases — a rejected request returns no rows; the limit holds for subsequent requests; requests within the limit are untouched (
end()is only on the rejection branch); and the 429 still carriesRetry-AfterandX-RateLimit-Limitper RFC 6585, sinceend()must not cost the headers set before it.765 unit, 338 standalone integration, all green. No existing test modified.
Filed, not fixed here
#127 — the global
rate_limit:block is documented (4 keys inCONFIG_REFERENCE.md), parsed, and read by nothing. Measured: a global limit of 2 lets request 3 and 4 straight through with no 429 at all. An operator configuring deployment-wide rate limiting today gets none. Making it live starts returning 429s to deployments that are currently unlimited, so it needs an owner decision and a release note rather than riding along here.Found by an agent-crew review of the request hot path; every claim above verified against a running server.
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.