fix(rate-limiter): default USE_REDIS_RATE_LIMITER to True for multi-worker safety - #246
Closed
LaGodxy wants to merge 1 commit into
Closed
fix(rate-limiter): default USE_REDIS_RATE_LIMITER to True for multi-worker safety#246LaGodxy wants to merge 1 commit into
LaGodxy wants to merge 1 commit into
Conversation
…orker safety The rate limiter default USE_REDIS_RATE_LIMITER=False forced every deployment to use SimpleRateLimiter with in-memory state. In a multi-worker Gunicorn setup each worker has its own memory space, allowing users to exceed rate limits by a factor of num_workers. Changed the default to True so Redis-backed rate limiting is used automatically when a broker is available, with the existing circuit breaker fallback to in-memory when Redis is unreachable. Closes ApexChainx#238
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.
Summary
Closes #238
Why
USE_REDIS_RATE_LIMITERdefaulted toFalse, forcing every deployment to useSimpleRateLimiterwith an in-process dict. In a multi-worker Gunicorn setup each worker has its own memory space, allowing users to exceed rate limits by a factor ofnum_workers. TheRedisRateLimiterimplementation (including Lua-script sliding window, circuit breaker, and graceful fallback) was fully written but never activated.What was built
app/core/config.pyUSE_REDIS_RATE_LIMITERdefault fromFalsetoTruetests/test_rate_limiter_multiworker.pyIntegration changes outside
<module>/No new env vars.
USE_REDIS_RATE_LIMITERis nowTrueby default — Redis must be available at startup for rate limiting to work across workers. The existing circuit breaker fallback to in-memory (SimpleRateLimiter) handles Redis unavailability gracefully.Acceptance criteria coverage
True)SimpleRateLimiter)test_rate_limiter_redis.pytests pass with the production implementation (no changes needed — they monkeypatch settings)Deliberately deferred
Test plan
pytest tests/test_rate_limiter_redis.py— 3/3 passingpytest tests/test_rate_limiter_multiworker.py— 5/5 passingEnv vars / Notes
USE_REDIS_RATE_LIMITERnow defaults toTrue. SetUSE_REDIS_RATE_LIMITER=falsein.envto force in-memory mode for single-worker local dev.