express-extras icon indicating copy to clipboard operation
express-extras copied to clipboard

Bugs in throttling control code?

Open wingc-china opened this issue 10 years ago • 0 comments

Hi express-extras author,

Thanks for making such simple package for simple throttling control. I started to use and I found there might be 2 bugs in the code:

In express-extras.js (116) if (hashList[key].count >= opts.urlCount) { This condition check makes no way to limit 1 call per given time. Because when the urlCount is set to 1, making one call always gets 1 that is equal to the limit and client gets error. Should we consider if (hashList[key].count > opts.urlCount) { or if (hashList[key].count >= opts.urlCount + 1) {?

In express-extras.js (125 - 127) setTimeout(function() { delete hashList[key]; }, (opts.urlCount + 1 * 1000)); The timeout value (opts.urlCount + 1 * 1000) seems not make sense. So after 1 second plus urlCount mill-seconds the in-held count and time stamp just expire? I suspect the timeout value should just be (opts.urlSec * 1000).

Thanks for your time to take a look. Hope I understand your code right.

wingc-china avatar Feb 11 '16 08:02 wingc-china