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

Race condition when using async.times #29

Closed
kp96 opened this issue Jan 31, 2017 · 0 comments
Closed

Race condition when using async.times #29

kp96 opened this issue Jan 31, 2017 · 0 comments

Comments

@kp96
Copy link
Contributor

kp96 commented Jan 31, 2017

When I tested the limiter with the code below

var redis = require('ioredis'),
  Limiter = require('ratelimiter'),
  async = require('async'),
  db = redis.createClient(),
  limiter;

limiter = new Limiter({
  id: 'hello',
  db: db
});

async.times(10, function(n, next) {
  limiter.get(next);
}, function(err, res) {
  console.log(res);
});

It printed the following

[ { total: 2500, remaining: 2500, reset: 1485859856 },
  { total: 2500, remaining: 2499, reset: 1485859856 },
  { total: 2500, remaining: 2499, reset: 1485859856 },
  { total: 2500, remaining: 2499, reset: 1485859856 },
  { total: 2500, remaining: 2499, reset: 1485859856 },
  { total: 2500, remaining: 2499, reset: 1485859856 },
  { total: 2500, remaining: 2499, reset: 1485859856 },
  { total: 2500, remaining: 2499, reset: 1485859856 },
  { total: 2500, remaining: 2498, reset: 1485859856 },
  { total: 2500, remaining: 2498, reset: 1485859856 } ]

Probably due to n value not getting updated. Sent a pr to try fixing this issue. Comments are appreciated.

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

No branches or pull requests

1 participant