Skip to content

ThrottlerStorage does not save the throttler object to map #2060

Open
@hcminh

Description

@hcminh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions