Skip to content

Commit 2ebea5e

Browse files
authored
Merge branch 'main' into logo
2 parents 3b95038 + f409610 commit 2ebea5e

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

docs/rate-limiting.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,5 @@ Rate limiting happens **before** the request is processed (at the middleware lay
182182

183183
- Rate limits are enforced across replicas as long as they share the same Redis instance.
184184
- The service verifies Redis connectivity at startup and fails fast when Redis is unavailable.
185+
- **Fail-open behaviour**: If Redis becomes unreachable at runtime, requests are allowed through without rate limiting (with a warning log). This prevents a Redis outage from causing a self-inflicted denial of service.
185186
- **In-transit encryption (TLS)**: Cloud Memorystore instances are created with `--transit-encryption-mode=SERVER_AUTHENTICATION`. Use the `rediss://` URL scheme and set `RATE_LIMIT_REDIS_CA_CERT` to the path of the mounted server CA certificate. See [Cloud Run Deployment — Redis Setup](../deploy/cloudrun/README.md#4-redis-setup-for-rate-limiting) for setup instructions.

src/lightspeed_agent/ratelimit/middleware.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,16 @@ async def dispatch(
271271
try:
272272
allowed, status = await self._limiter.is_allowed(principal_keys=principals)
273273
except RuntimeError:
274-
logger.error(
275-
"Rate limiter backend unavailable, returning 503 (principals=%s)",
274+
# Fail open: allow the request through when Redis is unavailable.
275+
# Blocking all traffic on a rate-limiter outage would be a
276+
# self-inflicted denial of service.
277+
logger.warning(
278+
"Rate limiter backend unavailable, allowing request (fail-open). "
279+
"principals=%s",
276280
principals,
277281
)
278-
return JSONResponse(
279-
status_code=503,
280-
content={
281-
"error": "rate_limiter_unavailable",
282-
"message": "Rate limiter backend unavailable",
283-
},
284-
)
282+
response = await call_next(request)
283+
return response
285284

286285
if not allowed:
287286
logger.warning(

0 commit comments

Comments
 (0)