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

fix(redis): throw error when passing points as non integer number #267

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

roggervalf
Copy link
Contributor

fixes #221

@@ -192,6 +192,10 @@ module.exports = class RateLimiterStoreAbstract extends RateLimiterAbstract {
* @returns Promise<RateLimiterRes>
*/
consume(key, pointsToConsume = 1, options = {}) {
if(!Number.isInteger(pointsToConsume)){
Copy link
Owner

Choose a reason for hiding this comment

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

@roggervalf What happens if pointsToConsume is string or float? This new check you're adding may be a little destructive for those who already consume points as floats or strings by mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you @animir and sorry for the delay. I just added few extra validations. I was doing some testing and when an string is passed for example 2.0, redis throws an error because it recognize it as non-integer

Copy link
Owner

@animir animir Nov 3, 2024

Choose a reason for hiding this comment

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

@roggervalf I am also very busy this autumn. No worries about the delay.

Just to clarify. Does RateLimiterRedis throw error when float number of points is consumed, but it isn't easy to understand the error source? Does your code improve the visibility of the error and it doesn't introduce any new error type, does it?

Copy link
Owner

Choose a reason for hiding this comment

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

@roggervalf Could you fix falling tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @animir sorry for the delay. It should be done

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks @roggervalf . I had another look at this PR and realized that common RateLimiterStoreAbstract maybe not a good place for this new check. What if other limiters work with floats and somebody uses that ability right now? We don't know.

Could you move this change to _upsert function in RateLimiterRedis? Here

async _upsert(rlKey, points, msDuration, forceExpire = false) {

@animir animir mentioned this pull request Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lua script takes non integer argument as input which causes random error on user supplied input
2 participants