fiber icon indicating copy to clipboard operation
fiber copied to clipboard

🐛 [Bug]: Rate limiter fails to reset after expiration window

Open hamidrabedi opened this issue 1 month ago • 2 comments

Bug Description

The rate limiter middleware stops allowing requests once the limit is reached and never resets, even after the expiration window has passed.

How to Reproduce

goapp.Use(limiter.New(limiter.Config{
    Max:        20,
    Expiration: 30 * time.Second,
}))

Expected Behavior

After 20 requests within 30 seconds, subsequent requests should be rate limited (429). Once the 30-second window expires, requests should succeed again (200).

Logs:

{"level":"info","ts":1763885420.00698,"caller":"[email protected]/zap.go:106","msg":"Success","ip":"127.0.0.1","latency":"33.893µs","status":200,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885430.0723326,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"7.067µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885440.1590369,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"12.539µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885450.2498455,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"5.84µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885460.6493433,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"8.911µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885470.7410114,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"6.363µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885480.8387995,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"6.318µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885490.9188917,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"5.812µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885500.9927847,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"5.594µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885511.0701776,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"6.188µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885521.1578481,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"5.618µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885531.2473729,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"6.843µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885541.3068976,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"5.966µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885551.4161906,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"5.991µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885561.528288,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"5.898µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885571.6134698,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"7.829µs","status":429,"method":"GET","url":"/ready"}
{"level":"warn","ts":1763885581.7208788,"caller":"[email protected]/zap.go:106","msg":"Client error","ip":"127.0.0.1","latency":"5.463µs","status":429,"method":"GET","url":"/ready"}

Fiber Version

v2.52.9

Code Snippet (optional)


Checklist:

  • [x] I agree to follow Fiber's Code of Conduct.
  • [x] I have checked for existing issues that describe my problem prior to opening this one.
  • [x] I understand that improperly formatted bug reports may be closed without explanation.

hamidrabedi avatar Nov 23 '25 11:11 hamidrabedi

@gaby, @hamidrabedi

Can I tackle this issue ? or is the priority on version 3 release ?

paooxide avatar Nov 24 '25 14:11 paooxide

@paooxide This is fixed in v3. I already have a fix for v2 will submit PR tonight.

gaby avatar Nov 24 '25 14:11 gaby