feat(server): Add HTTP concurrency limit with 503 rejection#326
Merged
feat(server): Add HTTP concurrency limit with 503 rejection#326
Conversation
Adds a web-tier flood protection limit to the objectstore server. When the number of in-flight HTTP requests reaches `http.max_requests` (default: 10,000), new requests are rejected immediately with HTTP 503. Health and readiness endpoints are excluded from the limit. The `Http` config struct groups HTTP-layer settings separately from the service-layer `Service` struct, providing a natural home for future HTTP-level settings such as timeouts and body size limits. Configurable via `OS__HTTP__MAX_REQUESTS`. Includes two unit tests (pass-through and rejection/exemption) using a `Notify`-based gating pattern, and an integration test via `TestServer` with `max_requests = 0` for deterministic coverage.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Router::layer() ordering is the inverse of ServiceBuilder — the last .layer() call is outermost (runs first). The test had in_flight_layer as outermost, so it incremented the counter before limit_web_concurrency checked it, causing the first request to be rejected immediately and the handler to never call paused.notify_one(), hanging the test indefinitely. Swap to apply in_flight_layer first (inner) and limit_web_concurrency second (outer), matching the production middleware order in app.rs. Also add a 5-second timeout around paused.notified() so the test fails with a clear message rather than hanging in CI.
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.
Adds a web-tier flood protection limit to the objectstore HTTP server. When the number of in-flight requests reaches
http.max_requests(default: 10,000), new requests are rejected immediately with HTTP 503./healthand/readyare excluded so orchestration probes always get through.The
Httpconfig struct groups HTTP-layer settings separately from the service-layerServicestruct. This keeps concerns cleanly separated and gives a natural home for future HTTP-level settings (timeouts, body size limits, etc.). The env var isOS__HTTP__MAX_REQUESTS.Why direct 503 instead of readiness-based backpressure: failing
/readyunder load lets Kubernetes drain the pod, but probe intervals (5–10s) leave a window of continued overload, recovery wastes capacity waiting for probe cycles, and multiple pods failing probes simultaneously concentrates traffic onto remaining pods. A busy pod is also semantically still ready — conflating load with readiness muddies alerting. Direct rejection responds in milliseconds, recovers instantly, keeps every pod in the pool, and works in any deployment environment.Tested with two unit tests (pass-through and rejection/exemption via a
Notify-based gating pattern) and an integration test viaTestServerwithmax_requests = 0for deterministic coverage without needing concurrent requests.Ref FS-171
Closes #315