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

serious bug: remaining times is stuck when use "storage" option with nestjs-redis #322

Closed
liaoliaots opened this issue Mar 23, 2021 · 7 comments

Comments

@liaoliaots
Copy link

liaoliaots commented Mar 23, 2021

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request

Current behavior

export const Throttler: DynamicModule = ThrottlerModule.forRootAsync({
  imports: [Redis],
  inject: [RedisService],
  useFactory(redisService: RedisService): ThrottlerModuleOptions {
    const redisClient = redisService.getClient(REDIS_CLIENT_NAME_THROTTLER);

    return {
      ttl: ms('1m') / 1000,
      limit: 30,
      storage: new ThrottlerStorageRedisService(redisClient),
    };
  },
});
  • The X-RateLimit-Remaining in headers of response is stuck when send request about 11-12 times.
  • But if not use "storage" option, it works normally.
  • I created a mini repo below for this issue.

Expected behavior

The throttler should works normally.

Minimal reproduction of the problem with instructions

  1. download from https://github.com/DevAngsy/throttle-bug
  2. npm install
  3. edit redis password according to your redis config
  4. npm run start:dev
  5. send get request to http://127.0.0.1:3000/app/hello 10-20 times, and notice X-RateLimit-Remaining
  6. single-line annotate "storage" option, notice X-RateLimit-Remaining again

Environment

OS Version: Ubuntu 20.04.2 LTS
CPU: Intel® Core™ i5-9600K
NodeJS Version: 14.16.0
NPM Version: 7.6.3
Ubuntu Redis Version: V6
Global Nest CLI Version: 7.5.6
Repo Nest CLI Version: 7.5.6
Repo nestjs-throttler Version: 0.3.0
Repo nestjs-throttler-storage-redis Version: 0.1.11
Repo ioredis Version: 4.24.3
@liaoliaots
Copy link
Author

see nestjs/throttler#416 (comment)

@kkoomen
Copy link
Owner

kkoomen commented Mar 26, 2021

So, the problem is that redis is only returning the last or first 10 items. I can increase this by simply adding COUNT with a value of 10000. I'll implement a fix asap.

@kkoomen
Copy link
Owner

kkoomen commented Mar 26, 2021

Latest 0.1.12 has the fix.

@liaoliaots
Copy link
Author

Thanks.

@elucidsoft
Copy link

This is still not fixed, it's still happening for me.

@elucidsoft
Copy link

The problem is, my main DB has over 2 million records in it. So switching this over to db1 fixed the issue.

@elucidsoft
Copy link

There is a pretty big bug here, since it uses the main db0 on your redis instance if you have any other data other than this in that DB it won't scan past the SCANCOUNT. So it simply doesn't work if your Redis DB is full of tons of data. You may want to rewrite this so it works differently.

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

3 participants