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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃┕ Fix limiter middleware db connection #1813

Merged
merged 6 commits into from Mar 15, 2022
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion middleware/limiter/limiter_fixed.go
Expand Up @@ -72,7 +72,6 @@ func (FixedWindow) New(cfg Config) fiber.Handler {
// Update storage
manager.set(key, e, cfg.Expiration)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think moving the set function must also be done in the part where the limit was reached


// Unlock entry
mux.Unlock()

// Check if hits exceed the cfg.Max
Expand All @@ -93,8 +92,12 @@ func (FixedWindow) New(cfg Config) fiber.Handler {
if (cfg.SkipSuccessfulRequests && c.Response().StatusCode() < fiber.StatusBadRequest) ||
(cfg.SkipFailedRequests && c.Response().StatusCode() >= fiber.StatusBadRequest) {
mux.Lock()

e = manager.get(key)
e.currHits--
remaining++
manager.set(key, e, cfg.Expiration)

mux.Unlock()
}

Expand Down