-
-
Notifications
You must be signed in to change notification settings - Fork 177
add timeout ms option #315
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
base: master
Are you sure you want to change the base?
Conversation
Hi @aclarembeau Thank you. It is interesting concept. From your experience what databases don't provide request timeout options? |
I can give redis as an example. If you use node flexible rate limiter as a rate limit solution for a low latency api, and your redis instance is not responding, you may have to wait for a full TCP keep alive + 1 TCP read timeout in order for redis to change its state and become non responsive. As this option is not configurable per instance on node redis, it means your public request may have to wait a few minutes before being processed (for instance by the insurance rate limiter). Thanks to this option, we can introduce a timeout for providers, like redis, that don't have a notion of per-request timeout. An alternative solution would have been to bring a timeout only for redis, but I suspect other engines may benefit from it too (for instance I don't see such a timeout in the options for postgres in the lib). Thank you |
@aclarembeau Thank you for the explanation. What do you think? |
Oh, indeed, if individual clients support it, there is no need to have a global timeout :) In that case, we can close this PR |
After having a second look, it seems that unfortunately, the node-redis options are not giving enough control: Citing their change: That means if the command is sent, but pending, even with a redis timeout, the command will hang |
@aclarembeau Hi.
Can command be sent to stale Redis server? I presume it won't accept TCP packages in this case. I don't know for a fact though. I suggest slightly more isolated approach.
Thoughts? |
You can have a situation where the command is issued, but the response never comes back, if the machine dies in the middle of the process. I'm not against the wrapper approach. That would be a nice way to extend the behavior of that library, but I'm wondering: is this something that is currently possible with the exposed API, or, we need to implement some kind of wrapper strategy? Thank you |
Good question. A wrapper should provide a way to set const limiterWithTimeouts = new RLWrapperTimeouts({
limiter: new RateLimiterRedis({ storeClient: redisClient }),
callTimeoutMs: 1000,
}) It would be good to have implemented all seven methods required by RateLimiterAbstract consume, penalty, reward, etc. |
Hi, I would also be interested in this feature. What is the status right now? |
@aclarembeau HI, is it in your nearest plans to continue? |
@florian-schunk Hi, it seems like |
Add configurable timeout option for consume operations
Hello :) And thank you for the impressive work the team have done on this amazing library.
This is my first contribution, so, feel free to tell me if I did anything wrong. I'm happy to improve the format / documentation / code of this PR.
What did I do
Adds a new timeout parameter to the consume method that allows operations to automatically fail after a specified number of milliseconds, providing better control over time-critical rate limiting scenarios.
Motivation
Rate limiting is often time-critical, and not all providers offer reliable global timeouts that can guarantee request processing within specific time constraints. This enhancement ensures that applications can implement robust fallback strategies when rate limiting operations take too long, improving overall system reliability and user experience.
Small note
In the original version of the MR (commit 1), I managed to achieve this without an else branch, as in JS, promises run as soon as they are defined. But, after a bit of thinking, I added an explicit else branch, which I found a bit easier to read (commit 2), even though this is only needed for readability.