feat: add global rate limiter shared across all clients#25
Merged
Conversation
- Implement singleton RateLimiter via get_global_rate_limiter() - Configurable via STEAM_RATE_LIMIT environment variable (default: 10 req/s) - All SteamClient instances share the global limiter by default - Add reset_global_rate_limiter() for testing - Add comprehensive unit tests for concurrent access 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Owner
Author
Code Review - Global Rate Limiter🔴 Critical: Race ConditionThe lock Fix: async def get_global_rate_limiter() -> RateLimiter:
global _global_rate_limiter
async with _global_rate_limiter_lock:
if _global_rate_limiter is None:
_global_rate_limiter = RateLimiter(
requests_per_second=float(os.getenv("STEAM_RATE_LIMIT", str(DEFAULT_RATE_LIMIT)))
)
return _global_rate_limiterNote: Changes signature to 🟡 Breaking ChangeRemoving 🟡 Minor
Review by @agent-ml-python-mcp-expert |
- Remove unused _global_rate_limiter_lock (race condition is not an issue due to GIL and synchronous RateLimiter.__init__) - Add docstring explaining thread-safety - Add backward compatibility for deprecated requests_per_second param - Add tests for backward compatibility and param precedence 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Owner
Author
Re-Review: Issues Addressed ✅
Verdict: Approve - Ready to merge. Review by @agent-ml-python-mcp-expert |
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
RateLimiterviaget_global_rate_limiter()functionSteamClientinstances share the global limiter by default, preventing rate limit violations under concurrent loadSTEAM_RATE_LIMITenvironment variable (default: 10 req/s)Changes
steam_client.py: Added module-level globals andget_global_rate_limiter()/reset_global_rate_limiter()functionssteam_client.py: ChangedSteamClient.__init__to accept optionalrate_limiterparameter (uses global by default)test_global_rate_limiter.py: New test file with comprehensive tests for singleton behavior, env var config, and concurrent accessTesting
Checklist from Issue
STEAM_RATE_LIMIT)asyncio.Lock)Closes #15
🤖 Generated with Claude Code