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

Documentation: Recommend against multiple rate_limit handlers with identical distributed storage configuration #61

Open
divergentdave opened this issue Jul 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@divergentdave
Copy link
Contributor

We ran into an issue when using this handler in a more complex configuration, and I think it might be worth mentioning in the distributed rate limiting documentation, or adding an additional example configuration file. We had previously instantiated multiple rate_limit handlers, each in a separate handler chain for various routes. We also had one top-level storage module definition (using Redis). When I snooped on Redis traffic, I noticed that there were multiple goroutines reading and writing storage at the same time, using the same keys (based on the instance ID). I think this meant that different rate_limit handlers were clobbering each others' state, and reading back state from other instances that may correspond to a different route and rate limit handler.

We fixed this by instantiating the rate_limit handler once as a named route, invoking the named route from each route's handler chain, and using variables to link together which route handled the request and which rate limiting zone was used. Alternatively, the problem could be avoided by using different storage configuration in each rate_limit handler, and setting key_prefix to something different in each, for example.

@mholt
Copy link
Owner

mholt commented Jul 12, 2024

That is a really interesting phenomenon, and a clever workaround! I agree we should probably fix this.

What if we roughly hash the handler's configuration and use that as a prefix or suffix to the storage key/filenames? Exactly identically-configured handlers would collide, but I dunno if that's a problem if they're identical?

@mholt mholt added the bug Something isn't working label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants