nestjs / throttler

A rate limiting module for NestJS to work with Fastify, Express, GQL, Websockets, and RPC 🧭
https://nestjs.com
MIT License
628 stars 59 forks source link

ThrottlerStorage does not save the throttler object to map #2060

Open hcminh opened 3 months ago

hcminh commented 3 months ago

Is there an existing issue for this?

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?

Other

No response

cleytonchagasbr commented 3 months ago

up!

micalevisk commented 3 months ago

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

jmcdo29 commented 3 months ago

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

why reproductions are required

himanshuchauhan981 commented 2 months ago

I am facing the same issue