Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(router): enable fail open on rate limit redis availability failure #1659

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Sam-tesouro
Copy link

@Sam-tesouro Sam-tesouro commented Mar 5, 2025

Motivation and Context

Per #1555

On testing a Cosmo Rate Limit implementation I discovered every request would get a 500 response if Redis is scaled to zero, or if authentication is malformed.

This small change introduces a fail open configuration bool on rate_limit that allows requests to succeed, albeit delayed by the timeout on failing to hit Redis per request.

With fail open enabled the server is also able to start up without Redis availability, when Redis comes back up it will begin rate limiting again.

The per request penalty can be ameliorated by setting tighter timeouts on your Redis connection, for example:
redis://:[email protected]:6379?read_timeout=20ms&write_timeout=20ms&max_retries=-1&dial_timeout=100ms

Potential improvements

This implementation is naive in that you will pay a per request penalty whenever Redis isn't available, this wouldn't be ideal in a situation where Redis isn't available for > 1 request at a time.

It would be better to implement an internal cache method where Redis availability could be polled to at some interval async to the request pipeline. Then the request threads could just read the cache to determine if they should proceed with rate limiting or fail open fast. The tradeoff being that you can't guarantee you tried to rate limit on each request.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.
  • Documentation has been updated on https://github.com/wundergraph/cosmo-docs.
  • I have read the Contributors Guide.

Testing this additional feature is challenging and would likely need to take place in integration tests, glad to make a stab at that if y'all are interested in moving forward with this!

@github-actions github-actions bot added the router label Mar 5, 2025
@Sam-tesouro Sam-tesouro marked this pull request as draft March 5, 2025 14:09
Sam-tesouro and others added 2 commits March 5, 2025 09:24
@Sam-tesouro Sam-tesouro marked this pull request as ready for review March 5, 2025 14:36
@Sam-tesouro Sam-tesouro marked this pull request as draft March 7, 2025 21:14
@Sam-tesouro Sam-tesouro marked this pull request as ready for review March 8, 2025 03:09
Copy link

@Tesouro-Chris Tesouro-Chris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants