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

ThrottlerStorage does not save the throttler object to map #2060

Open
2 of 4 tasks
hcminh opened this issue Jul 25, 2024 · 4 comments
Open
2 of 4 tasks

ThrottlerStorage does not save the throttler object to map #2060

hcminh opened this issue Jul 25, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@hcminh
Copy link

hcminh commented Jul 25, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I have followed this official document to install @nestjs/throttler. But it not working with the following config

app.module.ts

@Module({
  imports: [
    ThrottlerModule.forRoot([{
        ttl: 60000,
        limit: 3,
      }]),
    WebModule,
  ],
  controllers: [AppController],
  providers: [
    { provide: APP_GUARD, useClass: ThrottlerGuard },
    AppService,
  ],
})
export class AppModule {}

app.controller.ts

@Controller()
@Throttle({default: {limit: 3, ttl: 60000}})
export class AppController {
  constructor() {}

  @Get()
  hello(): string {
    return "hello"
  }
}

The response header I get overtime is

x-ratelimit-limit: 3
x-ratelimit-remaining: 2
x-ratelimit-reset: 60

Minimum reproduction code

n/a

Steps to reproduce

I have jumped to node_modules/nestjs/throttler to debug with console.log and found out that the throttlerStorage was not storing any upcoming requests. For any new request, function this.storage.get(key) always return undefined

image

the output log is
image

Expected behavior

The request should be stored and should throw ThrottlerError

Package version

6.0.0

NestJS version

10.3.3

Node.js version

v18.20.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@hcminh hcminh added the bug Something isn't working label Jul 25, 2024
@cleytonchagasbr
Copy link

up!

@micalevisk
Copy link
Member

micalevisk commented Jul 25, 2024

@cleytonchagasbr please avoid '+1' comments. If you agree with the issue, use the 👍 reaction instead.

@jmcdo29
Copy link
Member

jmcdo29 commented Jul 25, 2024

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

why reproductions are required

@himanshuchauhan981
Copy link

I am facing the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants