-
Notifications
You must be signed in to change notification settings - Fork 3
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
Race condition in Redis backend / design issue with the Backend
type
#7
Comments
Is this library safe to use while this race condition exists? |
Hi @qwbarch, sorry for the slight delay in getting back to you -- I somehow missed the notification for your reply here -- and sorry for not fixing this bug yet. To answer your question, it somewhat depends on which rate limiting strategy you plan to use and how much you care about strict enforcement of the policies. Generally speaking, I'd think that the library is safe to use until this is fixed. For the fixed window strategy, the race condition doesn't matter, because it will only call For the sliding window strategy, the race conditions comes into play if:
In short, it is unlikely to be exploitable by a malicious user and in the worst case would still rate limit calls within a given window. |
Doesn't seem too bad to stick with the sliding window strategy then. Thanks a lot for the detailed reply! |
Initially reported for
wai-rate-limit-postgres
by @chshersh and then @donatello forwai-rate-limit-redis
over in donatello/wai-rate-limit-postgres#7 (comment). The problem forwai-rate-limit-redis
specifically is thatEXPIRE
will not create the key if it doesn't already exist, which might be the case if it has expired between the calls tobackendIncAndGetUsage
andbackendExpireIn
.More generally, the problem extends to other backends, such as
wai-rate-limit-postgres
, since there is no way to run the two transactionally.The text was updated successfully, but these errors were encountered: