Attempting to use RateLimitLayer in tower::limit::rate
on Axum server not working
#1734
-
Long story short, I'm trying to extend an existing rate limiter. I copied the code exactly and made only one change in The problem is, when I try to modify the struct's field in the Service's My question is, what should I be doing so that I can modify the state field (or any field) within the Output:
Github reproducible code: https://github.com/khalludi/token-bucket-rl |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There is a reason tower's rate limiting middleware doesn't implement I answered a similar question previously. See #987 |
Beta Was this translation helpful? Give feedback.
There is a reason tower's rate limiting middleware doesn't implement
Clone
. By doing what you're doing your essentially bypassing the limiting by cloning everything. The clones don't actually share the underlying service, or the bookkeeping for how many requests have been sent.I answered a similar question previously. See #987